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.
Make Sure that
yourView.userInteractionEnabled = YES;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With