iOS 5 下不再调用 UITapGestureRecognizer 的目标
我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在我实现了所有三个委托方法(尽管它们是可选的),它可以工作了。只是返回默认值。谢谢邓克尔斯特恩和托马斯。
Now that I implement all three delegate methods (though they're optional) it works. Just returning the default values. Thanks, Dunkelstern and thomas.
尝试将 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.