简体   繁体   English

如何检测uisegmentedcontrol上的触摸 - 即使在选定的段上?

[英]how to detect touches on uisegmentedcontrol - even on selected segment?

While detecting changes works with UIControlEventValueChanged - I need to detect touches even on selected segments. 虽然检测到更改与UIControlEventValueChanged - 我甚至需要检测所选段上的触摸。

I tried 我试过了

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

But this fires nothing. 但这没什么。

Is there a way to detect touches on a selected segment? 有没有办法检测选定细分的触摸?

EDIT - without having to create a new subclass. 编辑 - 无需创建新的子类。 ps also the gesture recognizer does not accept the segmentcontrol when trying to drag it there ps也是手势识别器在尝试将其拖动到那里时不接受segmentcontrol

Many thanks 非常感谢

I think this 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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM