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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:24:17  来源:igfitidea点击:

Objective-c: How to detect double tap on view?

iphoneobjective-ciosipad

提问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 UITapGestureRecognizerto 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 UITapGestureRecognizerto the view, with numberOfTapsRequired = 2.

将 a 添加UITapGestureRecognizer到视图中,使用numberOfTapsRequired = 2.