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

后端 未结 2 915
半阙折子戏
半阙折子戏 2021-01-31 16:50

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 b

相关标签:
2条回答
  • 2021-01-31 16:57

    You need to add an UITapGestureRecognizer to the view which you want to be tapped.

    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
        }
    }
    
    0 讨论(0)
  • 2021-01-31 17:02

    Add a UITapGestureRecognizer to the view, with numberOfTapsRequired = 2.

    0 讨论(0)
提交回复
热议问题