如何向 UITableViewController 添加手势?
我想在继承自 UITableViewController 的视图上实现从右到左和从左到右的手势。我有在另一个视图(UIViewController)中实现的手势代码,它可以工作。
看起来 touchesBegan
甚至没有被调用。
有谁知道知道这样做吗?
谢谢
I want to implement right-to-left and left-to-right gestures on a view that inherits from UITableViewController. I have the code for the gestures implemented in another view (UIViewController) and it works.
It does't seem like touchesBegan
is even getting called.
Does anyone know know to do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于 SDK 版本。在3.2中,使用UIGestureRecognizer。 3.2 之前使用
touchesBegan
和朋友。在处理UIScrollView
时尤其如此,因为UIGestureRecognizer
将取消touchesBegan
。因此,如果你想向前和向后兼容,你必须使用 UIScrollView 来实现这两个功能。对于您的特定情况,请使用
UISwipeGestureRecognizer
或UIPanGestureRecognizer
。您必须实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:以防止UIScrollView取消您的手势识别器。It depends on the SDK version. In 3.2, use
UIGestureRecognizer
. Prior to 3.2 usetouchesBegan
and friends. This is especially true when dealing with aUIScrollView
becauseUIGestureRecognizer
will canceltouchesBegan
. So if you want to be forwards and backwards compatible you have to do both with a UIScrollView.For your particular case, use
UISwipeGestureRecognizer
orUIPanGestureRecognizer
. You will have to implementgestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
to prevent the UIScrollView from canceling your gesture recognizers.