如何检测UISwipeGestureRecognizer的结尾? [英] How to detect end of UISwipeGestureRecognizer?
问题描述
从Apple文档
滑动是一种离散手势,因此每个手势仅发送一次相关的动作消息.
A swipe is a discrete gesture, and thus the associated action message is sent only once per gesture.
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
当我使用UISwipeGestureRecognizer时也不会被调用
also doesn't gets called when I use UISwipeGestureRecognizer
如何检测用户何时抬起手指?
How can I detect when the user lifts his finger?
推荐答案
我弄清楚了,实际上很简单,而不是使用UISwipeGestureRecognizer来检测滑动,而是我自己使用事件处理来检测到它
I figured it out, actually it was quite easy, instead of using UISwipeGestureRecognizer to detect swipes I detected it myself using event handling
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
self.initialPosition = [touch locationInView:self.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint movingPoint = [touch locationInView:self.view];
CGFloat moveAmt = movingPoint.y - self.initialPosition.y;
if (moveAmt < -(minimum_detect_distance)) {
[self handleSwipeUp];
} else if (moveAmt > minimum_detect_distance) {
[self handleSwipeDown];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];
}
我没有将UIGestureRecognizer子类化,而是仅在必需的视图控制器中进行事件处理,因为在重置方法中,我正在重置属于该视图控制器的一些变量,计数器和计时器.
I haven't subclassed UIGestureRecognizer but did the event handling in the required view controller only, as in reset method I am resetting few variable, counters and timers belonging to the view controller.
这篇关于如何检测UISwipeGestureRecognizer的结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!