ios - UITapGestureRecognizer 不适用于 iOS9

标签 ios xcode uigesturerecognizer xcode7 ios9

我有一个使用 UITapGestureRecognizers 的应用程序这似乎在 iOS9 Beta 2 中不起作用。

调用成功

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

但它不会触发任何其他 UITapGesture 委托(delegate)方法。

当我在运行 iOS 8 的设备上运行相同的应用程序(来自 Xcode 7)时,它按预期工作。

还有人打这个吗?

下面是我如何初始化 UITapGestureRecognizer。 TapGestureRecognizerSetup

编辑
如果我在代码中而不是在 ViewController xib 中创建 UITapGestureRecognizer,它工作正常,所以在 iOS9 或其他东西中的 xib 解析有问题。

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

编辑2
如果我删除了 XIB 中的 GestureRecognizer 并使用 XCode 7 将其重新添加回来,它也能正常工作。 当我这样做时,它添加了 <pressTypeMask key="allowedPressTypes"/>进入 UITapGestureRecognizer 下的 xib。

最佳答案

似乎 iOS9 寻找一个 <pressTypeMask key="allowedPressTypes"/>手势识别器的 xml 中的行,没有它,点击识别器将无法工作。 要解决此问题,您可以在代码中构建识别器,将该行添加到 xml 中,或者删除并重新添加 Xcode 7 中的手势识别器,这将正确添加 pressTypeMask进入 xml。

我想知道苹果是否会修复 iOS9,使其在 XML 中没有该行的情况下工作,但就目前而言,这是一个简单的修复。

关于ios - UITapGestureRecognizer 不适用于 iOS9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31049033/

相关文章:

iphone - 手势识别器由于某种原因无法在 iPhone 上工作

ios - UIScreenEdgePanGestureRecognizer 无法识别右边缘的手势

ios - NSDateFormater - 返回同一年的 2015 年和 2016 年日期

ios - 更改颜色时 Swift 更新 UIColor

ios - 更新 watchOS 并发症的最佳方式

ios - Xamarin 上的 retrofit 更新包

ios - 为什么 UITableViewDataSource 或 UITableViewDelegate 不需要在 UITableView 中定义为弱?

ios - 成功构建后应用程序未在 Xcode 中执行

xcode - GOMobile "event/touch"包

objective-c - 是否可以使用 UITapGestureRecognizer initWithTarget :action: 发送对象