hzx*_*zxu 10 objective-c uisegmentedcontrol ios
有没有办法在UISegmentedControl中检测段的第二次点击?我发现:
但是,据说:
如果将分段控件设置为具有瞬时样式,则当用户触摸时,段不会将其自身显示为选中(蓝色背景).公开按钮始终是瞬间的,不会影响实际选择.
有没有办法检测第二次点击以及触发选择操作并将段显示为已选中?
如果没有直接的方法来做,我想的是,我首先momentary设置标志YES,然后在每次点击时,手动更新选择状态,但是我还需要更新/取消选择其他段.
谢谢
Vin*_*ier 16
解决方案是拥有UISegmentedControl的自定义子类,并像这样自己检查.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
current = self.selectedSegmentIndex;
[super touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if (current == self.selectedSegmentIndex)
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
Run Code Online (Sandbox Code Playgroud)
我在touchesBegan中有另一个解决方案,但它在iOS 7中不再起作用.在Stack Overflow上还有其他解决方案在iOS 6及更高版本中无效.
| 归档时间: |
|
| 查看次数: |
3684 次 |
| 最近记录: |