tags:

views:

749

answers:

3

I have custom slider that I use the following touch event to respond to:

[bSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

I find it very difficult to use, it does not respond to touches about 50% of the time. Compared to the volume slider with the music player that works great every time you touch it. Are there any secrets to creating a slider in code that will make it more responsive?

+1  A: 

The problem is the event you are tracking. UIControlEventTouchUpInside means that your -start method will only get called if you lift your finger up while it is still in the bounds of the control, something that's not easy to do on a slider.

What you probably want is UIControlEventTouchUpOutside and/or UIControlEventTouchDragExit, which will call -start either when you lift your finger outside of the control's bounds, or when your finger is dragged from within a control to outside its bounds, respectively.

See the UIControl reference for more info.

Martin Gordon
Thanks for the feedback but I released I copied the wrong line it the first time. I have fixed it and I am using the UIControlEventValueChanged.
Aaron
+3  A: 

I had the same problem with my custom UISlider and solved it by using a larger "thumb" image with transparency around the outside.

I also had problems with my callback function running slowly and causing the slider to be very laggy and clumsy to use, which I fixed by adding a simple check at the top of the function:

int val = ceil(sliderView.value);
if (val == _lastSliderVal) return;
_lastSliderVal = val;

// .. code to update various display elements based on slider value

After changing both of these, the slider works beautifully.

pix0r
A: 

Well I tried several things including the suggestions above but never got my slider to work as well as the iPhone volume slider in the music app. The only thing that helped was to add a clear background around the button image to make the touch space larger. That created problems getting the button to slide all the way to the bottom and top of slider that I never completely resolved. Now with OS 3.0 is seems to be working much better.

Aaron