UITapGestureRecognizer没有做任何事情 [英] UITapGestureRecognizer not doing anything

查看:89
本文介绍了UITapGestureRecognizer没有做任何事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序显示一个文本页面,可以点击按钮或在视图中滑动以进入或退回各个页面。容器视图附加了两个UISwipeGestureRecognizer,用于向左滑动和向右滑动。这些手势没有问题。但是现在我正在尝试将UITapGestureRecognizer添加到另一个视图中,提供类似于iBooks或Kindle应用程序的功能,点击左侧返回,右侧继续前进。我所做的一切都无法触发。没有暗示它被触发,即使我将手势放在我的最顶层视图上并禁用其他手势。

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.

视图控制器实现了UIGestureRecognizerDelegate,尽管我没有需要实现委托方法。我确实尝试过实现shouldReceiveTouch:没有成功。

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];


推荐答案

在您添加手势的视图上尝试此操作识别器:

Try this on the view you're adding the gesture recognizers:

view.userInteractionEnabled = YES;

这篇关于UITapGestureRecognizer没有做任何事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆