Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITapGestureRecognizer not working

Tags:

iphone

UITapGestureRecognizer is not working for me, I wonder if anyone can help.

Here is my view definition:

@interface MainDisplayView : UIView <UIGestureRecognizerDelegate>

In the implementation, I have this in a method which is definitely being called:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToPrevious:)];
[tapRecognizer setDelegate:self];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setNumberOfTouchesRequired:1];
[myView addGestureRecognizer:tapRecognizer];

as well as this method:

- (void)goToPrevious:(UITapGestureRecognizer*)recognizer {
    NSLog(@"GO TO PREVIOUS");
}

I am testing in the simulator, and clicking in "myView" - but nothing happens. Thanks a lot!

Edited the code formatting.

like image 434
user1052610 Avatar asked Jan 02 '12 21:01

user1052610


2 Answers

Make Sure that

yourView.userInteractionEnabled = YES;

like image 62
Islam Adel Avatar answered Nov 16 '22 09:11

Islam Adel


Make sure that you view is not transparent - set a background color:

view.backgroundColor = [UIColor whiteColor];

Gesture recognizer will also not work when view's alpha is very close to 0.0.

like image 1
kam800 Avatar answered Nov 16 '22 09:11

kam800