如何在3.2以下的iOS中获得长按手势的功能
UILongPressGesture 在 ios 版本 3.2 及更高版本中可用。但我正在尝试开发应用程序以实现最大兼容性,因此针对 ios ver2.0
任何人都可以指导我如何在 ios v2.0 中完成长按手势
UILongPressGesture is available in ios ver 3.2 and later. But i am trying to develop application for maximum compatibility and hence targeting ios ver2.0
Can anyone please guide me on how to accomplish long press gesture in ios v2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于单个手指,这非常简单:在
touchesBegan
方法中启动一个计时器,并在计时器触发时触发一个操作。如果在触发之前收到touchesEnded
消息,请取消计时器。下面是使用performSelector:withObject:afterDelay:
方法的实现。如果手指移动得太远,您可能还想终止计时器。
对于多点触控,情况会稍微复杂一些。您必须跟踪哪个触摸是哪个触摸,并决定要做什么,例如,当一个手指按下足够长的时间而另一根手指没有按下时(或者弄清楚
UILongPressGestureRecognizer
做了什么)。For a single finger, it's pretty simple: Start a timer in the
touchesBegan
method and trigger an action when the timer fires. Cancel the timer if you get atouchesEnded
before it fires. Here's an implementation that uses theperformSelector:withObject:afterDelay:
method.You'll probably also want to kill the timer if the finger moves too far.
With multitouch, it's a bit more complicated. You'll have to keep track of which touch is which, and decide what to do e.g. when one finger has pressed long enough but the other hasn't (or figure out what
UILongPressGestureRecognizer
does).在您的视图中实现
touches...
方法。如果在touchesBegan:withEvent:
和touchesEnded:withEvent:
之间经过一定时间而没有任何touchesMoved:withEvent:
事件,则您有一个很长的时间按。Implement the
touches...
methods in your view. If a certain amount of time passes betweentouchesBegan:withEvent:
andtouchesEnded:withEvent:
without anytouchesMoved:withEvent:
events, you have a long press.