Domanda

When releasing the touch on a UISlider the value of the slider changes slightly and uncontrollably. It's so sensitive that it even changes when just releasing the finger from the screen. How can I achieve that the user can set a value he wants without problems?

That's how I create my UISlider:

UISlider *slider = [[UISlider alloc] initWithFrame: CGRectMake(100.0, 100.0, 200.0, 40.0)];
slider.minimumValue = 0.0;
slider.maximumValue = 100.0;
[slider addTarget: self action: @selector(sliderChanged:event:) forControlEvents:UIControlEventAllEvents];
[slider setValue: 50.0 animated: NO];
È stato utile?

Soluzione

You are registering it for all events. Make it for your event only like

[slider addTarget: self action: @selector(sliderChanged:event:) forControlEvents: UIControlEventTouchDragInside];

Altri suggerimenti

Try changing it to this instead:

[slider addTarget: self action: @selector(sliderChanged:event:) forControlEvents: UIControlEventValueChanged];

And if all you want is to trigger the target only when the finger is lifted, try setting continuous property of the UISlider to NO.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top