UITapGestureRecognizer 不执行任何操作
我有一个应用程序,可以显示一页文本,可以点击按钮或在视图中滑动以在各个页面中前进或后退。容器视图附加了两个 UISwipeGestureRecognizer,用于向左滑动和向右滑动。这些手势没有任何问题。但现在我正在尝试将 UITapGestureRecognizer 添加到另一个视图中,提供类似于 iBooks 或 Kindle 应用程序的功能,点击左侧返回,点击右侧前进。我所做的任何事情都无法让手势启动。即使我将手势放在最上面的视图上并禁用其他手势,也没有任何迹象表明它会被触发。
视图控制器实现 UIGestureRecognizerDelegate,尽管我不需要实现委托方法。我确实尝试实现 shouldReceiveTouch: 但没有成功。
这是我创建并附加手势识别器的代码片段:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureTurnPage:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
I've got an app that displays a page of text with the ability to tap a button or swipe in a view to advance or retreat through various pages. The container view has two UISwipeGestureRecognizers attached, for swipe left and swipe right. No trouble with these gestures. But now I'm trying to add UITapGestureRecognizer to another view, providing an ability similar to iBooks or the Kindle app, tap the left to go back, the right to go forward. Nothing I do can get the gesture to fire. No hint that it is ever being triggered, even if I put the gesture on my topmost view and disable other gestures.
The view controller implements UIGestureRecognizerDelegate, though I've not needed to implement delegate methods. I did try implementing shouldReceiveTouch: without success.
Here's a snippet of code where I create and attach the gesture recognizer:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureTurnPage:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您要添加手势识别器的视图上尝试此操作:
Try this on the view you're adding the gesture recognizers:
您提到您已经尝试过此操作,但以防万一再次尝试。
尝试在标头中使用带有
的委托,然后设置委托:然后实现此方法:
然后使用调试器或将
NSLog
放入上述方法中并还可以tapGestureTurnPage:
查看是否正在调用这些方法。You mention that you've tried this, but just in case go through it again.
Try using the delegate with
<UIGestureRecognizerDelegate>
in the header and then setting the delegate:Then implement this method:
Then use a debugger or toss an
NSLog
into the above method and alsotapGestureTurnPage:
to see if these methods are being called.在初始化手势的地方添加这个:
并在“self”类中添加这个:
这允许我在 UIWebView 上识别手势,并且 UIWebView 仍然会响应点击。 (我想要的 - 你可能不想要)
Add this where you initialize the gesture:
and add this in the "self" class:
This allows me to have gestures recognized on the UIWebView, and the UIWebView will still respond to the taps. (which i wanted - you may not)