iOS 5 下不再调用 UITapGestureRecognizer 的目标

发布于 2024-12-11 15:23:57 字数 942 浏览 0 评论 0原文

我已经使用 UITapGestureRecognizer 一段时间了,以便在点击发生时注意到并显示另一个视图。我像这样初始化它:

_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showModalDetailView:)];

在 iOS 4.3 中,这确实工作得很好。在 iOS 5 中,-showModalDetailView: 不再被调用。

我想知道其他人是否也有这个问题?

更新

我正在像这样配置识别器:

_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showModalDetailView:)];
_tapGesture.numberOfTapsRequired = 1;
_tapGesture.numberOfTouchesRequired = 1;
_tapGesture.delegate = self;
[self addGestureRecognizer:_tapGesture];

更新 2

好吧,现在它变得很奇怪。一旦我通过注释禁用委托设置,代码就会再次开始工作。但是,委托方法仍在被调用。但并非总是如此。

该单元格具有左对齐标题和右对齐详细文本。当您点击详细文本时,它会按预期工作:委托方法不会被调用,并且会出现弹出窗口。当您点击其他位置的单元格时,委托方法(在本例中为 -gestureRecognizer:shouldReceiveTouch:)将被调用并出现弹出窗口。

我不太明白这里发生了什么事。

I've been using a UITapGestureRecognizer for quite some time now to take notice when a tap occurs and to display another view. I'm initializing it like this:

_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showModalDetailView:)];

In iOS 4.3, that did work perfectly. In iOS 5, -showModalDetailView: does not get called anymore.

I was wondering if anyone else has this issue, too?

Update

I'm configuring the recognizer like this:

_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showModalDetailView:)];
_tapGesture.numberOfTapsRequired = 1;
_tapGesture.numberOfTouchesRequired = 1;
_tapGesture.delegate = self;
[self addGestureRecognizer:_tapGesture];

Update 2

Ok, now it gets weird. The code starts working again once I disable the delegate setting by commenting it. However, the delegate methods are still being called. But not always.

The cell has a left aligned title and a right aligned detail text. When you hit the detail text it works as expected: The delegate method does not get called and the popover appears. When you hit the cell somewhere else, the delegate method (-gestureRecognizer:shouldReceiveTouch: in this case) gets called and the popover appears.

I don't quite get what's going on here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-12-18 15:23:57

现在我实现了所有三个委托方法(尽管它们是可选的),它可以工作了。只是返回默认值。谢谢邓克尔斯特恩和托马斯。

Now that I implement all three delegate methods (though they're optional) it works. Just returning the default values. Thanks, Dunkelstern and thomas.

走野 2024-12-18 15:23:57

尝试将 numberOfTouchesRequired 和 numberOfTapsRequired 显式设置为 1。
当然,您必须在 View 实例上调用 addGestureRecognizer。

Try setting numberOfTouchesRequired and numberOfTapsRequired to 1 explicitly.
And of course you have to call addGestureRecognizer on your View instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文