ios Objective-c:如何检测视图中的双击?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7316169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Objective-c: How to detect double tap on view?
提问by Azhar
I am developing an application where I have multiple controls on view but I want to enable them when user double tap the view
我正在开发一个应用程序,其中我有多个视图控件,但我想在用户双击视图时启用它们
You can take the example of double click but in device I want to catch the event when their is double tap.
您可以以双击为例,但在设备中,我想在双击时捕获事件。
回答by xuzhe
You need to add an UITapGestureRecognizer
to the view which you want to be tapped.
您需要向UITapGestureRecognizer
要点击的视图添加。
Like this:
像这样:
- (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
}
}
回答by Morrowless
Add a UITapGestureRecognizer
to the view, with numberOfTapsRequired = 2
.
将 a 添加UITapGestureRecognizer
到视图中,使用numberOfTapsRequired = 2
.