How to recognize touches by uisegmentedcontrol - even on a selected segment?

When detecting changes, it works with UIControlEventValueChanged - I need to detect touches even on selected segments.

I tried

  [onOffSC addTarget:self action:@selector(segmentedControlPushed) forControlEvents:UIControlEventAllTouchEvents]; 

But it doesn’t work.

Is there a way to detect touches on a selected segment?

EDIT - without creating a new subclass. ps also the gesture recognizer does not take control of the segment when trying to drag it there

Many thanks

+6
source share
1 answer

I think it will work

 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSInteger oldValue = self.selectedSegmentIndex; [super touchesBegan:touches withEvent:event]; if ( oldValue == self.selectedSegmentIndex ) [self sendActionsForControlEvents:UIControlEventValueChanged]; } 
+2
source

Source: https://habr.com/ru/post/920940/


All Articles