UITapGestureRecognizer not working on iOS9

I have an application which uses

UITapGestureRecognizers
which seem to not work in iOS9 Beta 2.

They are successfully calling

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 
NSLog(@"shouldReceiveTouch"); return YES; 
}

but it doesn't hit any of the other UITapGesture delegate methods.

When I run the same application (from Xcode 7) on a device running on iOS 8, it works as expected.

Has anyone else hit this?

Post not yet marked as solved Up vote post of Liron Down vote post of Liron
5.3k views

Replies

me 2!!!

Same here! -- tap works from Xcode 7 with iOS 8, does not with iOS 9 beta 2


long press fails the same way

If I built the taps in code, or if I deleted the UITapGestureRecognizer from the xib and added it back again, it worked.


I also noticed that when I did this in the xib, it removed

<pressTypeMask key="allowedPressTypes"/>

from the xml.

I can confirm that removing and re-adding the gesture recognizer in the storyboard fixed it. My guess is it's an issue with the latest build (v7 Beta 2).

I think you mean it adds

<pressTypeMask key="allowedPressTypes"/>

?

Yeah, you're right - I was misreading the diff in SourceTree. It *adds* that key in XCode 7.

Just ran into this myself. Filed bug # 21633089.

Try to add gestureRecognizer by code, it will work. Add gestureRecognizer from intefaceBuilder will have this problem.

I have my TapGestureRecognizer added by code and it only works on iOS 8.

You can also do this without using pressesBegan
Code Block
open class MenuUIPress : UIPress {
  weak var view: UIView?
  init(view: UIView) {
    self.view = view
  }
  open override var timestamp: TimeInterval {
    Date().timeIntervalSince1970
  }
  open override var phase: UIPress.Phase {
    UIPress.Phase.began
  }
  open override var type: UIPress.PressType {
    UIPress.PressType.menu
  }
  open override var window: UIWindow? {
    view?.window
  }
  open override var responder: UIResponder? {
    view
  }
  open override var gestureRecognizers: [UIGestureRecognizer]? {
    return view?.gestureRecognizers
  }
}
class SignInViewController {
func viewDidLoad() {
setUpTapGesture()
}
   private func setUpTapGesture() {
    #if os(tvOS)
      let tap = UITapGestureRecognizer()
      tap.allowedPressTypes = [NSNumber(value: UIPress.PressType.menu.rawValue)]
      tap.addTarget(self, action: #selector(SignInViewController.sendEndMenuTap))
      view.addGestureRecognizer(tap)
    #endif
  }
  @objc func sendEndMenuTap(_ gestureRecognizer: UITapGestureRecognizer) {
    print("@@@@@ called on touch end 3 state=", gestureRecognizer.state.rawValue)
    UIApplication.shared.pressesEnded([MenuUIPress(view: view)], with: UIPressesEvent())
  }
}