6

虽然检测更改适用UIControlEventValueChanged- 我需要检测即使在选定段上的触摸。

我试过

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

但这不会触发任何事情。

有没有办法检测选定段上的触摸?

编辑 - 无需创建新的子类。ps 手势识别器在尝试将其拖到那里时也不接受段控件

非常感谢

4

1 回答 1

2

我认为这会奏效

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSInteger oldValue = self.selectedSegmentIndex;
    [super touchesBegan:touches withEvent:event];
    if ( oldValue == self.selectedSegmentIndex )
        [self sendActionsForControlEvents:UIControlEventValueChanged];
}
于 2012-07-20T07:35:42.657 回答