Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 275
Azhar Avatar asked Sep 06 '11 07:09

Azhar


2 Answers

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     } } 
like image 159
xuzhe Avatar answered Sep 28 '22 08:09

xuzhe


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

like image 33
Morrowless Avatar answered Sep 28 '22 10:09

Morrowless