Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

ios - 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?

Here is how I initialise the UITapGestureRecognizer. TapGestureRecognizerSetup

Edit
If I create the UITapGestureRecognizer in code instead of in the ViewController xib it works fine, so there's something up with the xib parsing in iOS9 or something.

_tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMainViewTap:)];
_tapGesture2.numberOfTapsRequired = 1;
_tapGesture2.delegate = self;
[self.view addGestureRecognizer:_tapGesture2];

Edit2
If I deleted the GestureRecognizer in the XIB and added it back in again using XCode 7, it also worked. When I did this, it added <pressTypeMask key="allowedPressTypes"/> into the xib under the UITapGestureRecognizer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that iOS9 looks for a <pressTypeMask key="allowedPressTypes"/> line in the xml of the gesture recognizer and the tap recognizer doesn't work without it. To fix you can either build your recognizers in code, add that line into the xml or delete and re-add the gesture recognizer in Xcode 7, which will properly add the pressTypeMask into the xml.

I wonder if apple will fix iOS9 to work without that line in the XML, but for now, this is an easy fix.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...