【发布时间】:2015-06-25 11:25:51
【问题描述】:
我有一个使用 UITapGestureRecognizers 的应用程序,它似乎在 iOS9 Beta 2 中不起作用。
他们调用成功了
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog(@"shouldReceiveTouch");
return 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];
编辑2
如果我删除了 XIB 中的 GestureRecognizer 并使用 XCode 7 再次添加它,它也可以工作。
当我这样做时,它会将<pressTypeMask key="allowedPressTypes"/> 添加到 UITapGestureRecognizer 下的 xib 中。
【问题讨论】:
-
您是否将视图的属性“已启用用户交互”设置为“是”?也许视图没有正确处理触摸
-
它设置为 YES,但好主意:)。
-
我在应用程序中使用两个不同的 UITapGestureRecognizers 时遇到了同样的问题,它们在 iOS 8 中都可以正常工作。
-
另一点 - UISwipeGestureRecognizers 似乎工作正常。
-
可以确认这一点。我有一些旧的带有 IB 手势识别器的示例项目不起作用,只需在 .storyboard 文件中的条目中添加该晦涩的
<pressTypeMask key="allowedPressTypes"/>行即可修复它们的行为。
标签: ios xcode uigesturerecognizer xcode7 ios9