如何在iOS 3.2以下的iOS中获得Long Press手势的功能 [英] How to get functionality of Long Press gesture in iOS below 3.2
问题描述
UILongPressGesture可在ios ver 3.2及更高版本中使用。但我正在尝试开发最大兼容性的应用程序,因此定位ios ver2.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
任何人都可以指导我如何在ios v2.0中完成长按手势
Can anyone please guide me on how to accomplish long press gesture in ios v2.0
推荐答案
对于单个手指,它非常简单:在 touchesBegan $ c $中启动计时器c>方法并在计时器触发时触发一个动作。如果在触发之前获得
touchesEnded
,请取消计时器。这是一个使用 performSelector:withObject:afterDelay:
方法的实现。
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 a touchesEnded
before it fires. Here's an implementation that uses the performSelector:withObject:afterDelay:
method.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self performSelector:@selector(fireLongPress)
withObject:nil
afterDelay:LONG_PRESS_THRESHOLD];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
- (void)fireLongPress {
// do what you want to do
}
如果手指移得太远,你可能还想杀死计时器。
You'll probably also want to kill the timer if the finger moves too far.
多点触控,它有点复杂。你必须跟踪哪个触摸是哪个,并决定做什么,例如当一根手指按压的时间足够长但另一只手指没有按下时(或弄清楚 UILongPressGestureRecognizer
是什么)。
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).
这篇关于如何在iOS 3.2以下的iOS中获得Long Press手势的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!