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