问题描述
我有一个使用 UITapGestureRecognizers
的应用程序,它似乎在iOS9 Beta 2中不起作用。
它们是成功调用
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog(@shouldReceiveTouch);
返回YES;
}
但它没有达到任何其他UITapGesture委托方法。
当我在iOS 8上运行的设备上运行相同的应用程序(来自Xcode 7)时,它按预期工作。
以下是我初始化UITapGestureRecognizer的方法。
编辑
如果我在代码中而不是在ViewController xib中创建UITapGestureRecognizer它可以正常工作,所以iOS9中的xib解析就可以了。
_tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMainViewTap :)];
_tapGesture2.numberOfTapsRequired = 1;
_tapGesture2.delegate = self;
[self.view addGestureRecognizer:_tapGesture2];
Edit2
如果我删除了GestureRecognizer in XIB并使用XCode 7将其重新添加回来,它也有效。
当我这样做时,它在UITapGestureRecognizer下的xib中添加了< pressTypeMask key =allowedPressTypes/>
。
iOS9似乎在查找< pressTypeMask key =allowedPressTypes/>
行如果没有它,手势识别器的xml和点击识别器就无法工作。
要修复,您可以在代码中构建识别器,将该行添加到xml中或删除并在Xcode 7中重新添加手势识别器,这将正确添加 pressTypeMask
进入xml。
我想知道苹果是否会修复iOS9无法在XML中使用该行,但是现在,这是一个简单的修复。
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.
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.
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.
这篇关于UITapGestureRecognizer无法在iOS9上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!