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

后端 未结 2 916
半阙折子戏
半阙折子戏 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
        }
    }
    

提交回复
热议问题