UITapGestureRecognizer tap on self.view but ignore subviews

You should adopt the UIGestureRecognizerDelegate protocol inside the self object and call the below method for checking the view. Inside this method, check your view against touch.view and return the appropriate bool (Yes/No). Something like this: – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:yourSubView]) { return NO; } return YES; } Edit: Please, also … Read more

How do I implement the UITapGestureRecognizer into my application

This is a step by step guide on how to implement gesture recognizers in your class: Conform your class to UIGestureRecognizerDelegate protocol. Instantiate the gesture recognizer. For example, to instantiate a UITapGestureRecognizer, we will do: UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)]; Here, action is the selector which will handle the gesture. Here, our selector … Read more

ScrollView gesture recognizer eating all touch events

This should solve your problem. Detect touch event on UIScrollView AND on UIView’s components [which is placed inside UIScrollView] The idea is to tell the gesture recognizer to not swallow up the touch events. To do this you need to set singleTap’s cancelsTouchesInView property to NO, which is YES by default. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer … Read more

UITapGestureRecognizer – single tap and double tap

UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease]; singleTap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)] autorelease]; doubleTap.numberOfTapsRequired = 2; [self.view addGestureRecognizer:doubleTap]; [singleTap requireGestureRecognizerToFail:doubleTap]; Note: If you are using numberOfTouchesRequired it has to be .numberOfTouchesRequired = 1; For Swift let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(didPressPartButton)) singleTapGesture.numberOfTapsRequired = 1 view.addGestureRecognizer(singleTapGesture) let … Read more

How to tap to zoom and double tap to zoom out in iOS?

You need to implement UITapGestureRecognizer – docs here – in your viewController – (void)viewDidLoad { [super viewDidLoad]; // what object is going to handle the gesture when it gets recognised ? // the argument for tap is the gesture that caused this message to be sent UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)]; UITapGestureRecognizer *tapTwice … Read more

UITapGestureRecognizer – make it work on touch down, not touch up?

Use a UILongPressGestureRecognizer and set its minimumPressDuration to 0. It will act like a touch down during the UIGestureRecognizerStateBegan state. For Swift 4+ func setupTap() { let touchDown = UILongPressGestureRecognizer(target:self, action: #selector(didTouchDown)) touchDown.minimumPressDuration = 0 view.addGestureRecognizer(touchDown) } @objc func didTouchDown(gesture: UILongPressGestureRecognizer) { if gesture.state == .began { doSomething() } } For Objective-C -(void)setupLongPress { self.longPress … Read more

UIButton inside a view that has a UITapGestureRecognizer

You can set your controller or view (whichever creates the gesture recognizer) as the delegate of the UITapGestureRecognizer. Then in the delegate you can implement -gestureRecognizer:shouldReceiveTouch:. In your implementation you can test if the touch belongs to your new subview, and if it does, instruct the gesture recognizer to ignore it. Something like the following: … Read more

UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath

Ok, finally found it after some searching through gesture recognizer docs. The solution was to implement UIGestureRecognizerDelegate and add the following: #pragma mark UIGestureRecognizerDelegate methods – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:autocompleteTableView]) { // Don’t let selections of auto-complete entries fire the // gesture recognizer return NO; } return YES; } That took … Read more