检测平移手势结束 [英] Detecting Pan Gesture End

查看:77
本文介绍了检测平移手势结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,并且对此视图应用了UIPanGestureRecogniser:

I've got a view and I applied a UIPanGestureRecogniser to this view:

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAnim:)];
[sliderView addGestureRecognizer:panGesture];
[panGesture release];

我可以很好地检测和处理手势.但是,我希望在手势结束后再启动另一种方法.

I can detect and process the gesture just fine. However, I wish to initiate another method once the gesture has ended.

我知道有两种方法可以进行这种检测.但是,我发现touchesEndedtouchesCancelled会在触摸变为手势后立即被调用,即,我移动手指足以保证手势调用,而touchesEnded很少(如果有的话)会被调用.

I know there are two methods that allow this kind of detection. touchesEnded and touchesCancelled however, I've found that touchesCancelled gets called as soon as the touch becomes a gesture i.e. I move my finger enough to warrant a gesture call and touchesEnded rarely, if ever, gets called.

我希望能够向左/向右平移,然后在手势结束时启动另一个功能调用.我该怎么做?

I want to be able to pan left / right and then initiate another function call upon gesture ending. How do I do this?

推荐答案

可以通过使用UIGestureRecognizerStateEnded检查状态来检测到手势结束事件.

Pan gesture end event can be detected by checking the it's state with UIGestureRecognizerStateEnded.

检查以下代码.

-(void) panAnim:(UIPanGestureRecognizer*) gestureRecognizer
{
   if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
   {
      //All fingers are lifted.
   }
}

摘自Apple文档

平移手势是连续的.它 开始(UIGestureRecognizerStateBegan) 当最小手指数 允许(minimumNumberOfTouches)具有 移动足够被视为平底锅. 它改变 (UIGestureRecognizerStateChanged)何时 至少在手指移动的同时 最小手指数 下.结束了 (UIGestureRecognizerStateEnded)何时 所有手指都松开了.

A panning gesture is continuous. It begins (UIGestureRecognizerStateBegan) when the minimum number of fingers allowed (minimumNumberOfTouches) has moved enough to be considered a pan. It changes (UIGestureRecognizerStateChanged) when a finger moves while at least the minimum number of fingers are pressed down. It ends (UIGestureRecognizerStateEnded) when all fingers are lifted.

了解有关UIPanGestureRecognizer的更多信息

这篇关于检测平移手势结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆