Uilongpressesture在iOS Ver 3.2及以后提供。但是我正在尝试开发最大兼容性的应用程序,因此针对iOS Ver2.0

任何人都可以指导我如何完成iOS v2.0中的长期新闻姿态

有帮助吗?

解决方案

对于一根手指,这很简单:在 touchesBegan 方法并触发计时器发射时的动作。如果您得到一个计时器,请取消计时器 touchesEnded 在开火之前。这是使用 performSelector:withObject:afterDelay: 方法。

- (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
}

如果手指移动得太远,您可能还想杀死计时器。

使用Multitouch,它更加复杂。您必须跟踪哪个触摸是哪个触摸,并决定该怎么做,例如一根手指的压力足够长,而另一个手指还没有(或弄清楚什么 UILongPressGestureRecognizer 做)。

其他提示

实施 touches... 视图中的方法。如果一定的时间在 touchesBegan:withEvent:touchesEnded:withEvent: 没有任何 touchesMoved:withEvent: 事件,您的新闻发布会很长。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top