Вопрос

I have a series of segmented controls that call methods when a "Value Changed" event occurs.

My problem is that the values change if a user performs multi-touch gestures that begin on the controls: a four finger swipe up (to switch apps) or a five finger pinch (return to home screen). I've tried changing the methods to respond only to "Touch Up Inside" events, but the segmented controls still change values with the multi-touch gestures regardless.

Is there some way to subclass UISegmentedControl so that UIControlEventValueChanged only occurs for the controls if there is a "touch up inside" event for an individual segment?

Many thanks!

Это было полезно?

Решение

The problem is that you're having your UISegmentedControl respond to "UIControlEventValueChanged". If you only want your method to be called when you touch up inside then instead have the UISegmentedControl respond to "UIControlEventTouchUpInside". You shouldn't need to subclass or override anything.

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(yourMethod:)
 forControlEvents:UIControlEventTouchUpInside];

The available control events are found here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top