我正在开发一个应用程序,我在视图上有多个控件,但我想在用户双击视图时启用它们
您可以采用双击的示例,但在设备中,我想在双击时捕捉到该事件。
答案 0 :(得分:77)
您需要在要点按的视图中添加UITapGestureRecognizer
。
像这样:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
}
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized) {
// handling code
}
}
答案 1 :(得分:8)
使用UITapGestureRecognizer
在视图中添加numberOfTapsRequired = 2
。