ios - UIPanGestureRecognizer : Why there is no StateEnded every time

标签 ios objective-c ios7

我正在使用 UIPanGestureRecognizer 来检测和计算手指的移动。我的问题是触发了以下事件序列:

状态开始 状态改变 状态改变 状态改变 状态结束

但有时同一用户交互只有这个序列

状态改变 状态改变 状态改变

- (void)viewDidLoad
{
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
panRecognizer.minimumNumberOfTouches = 1;
panRecognizer.maximumNumberOfTouches = 1;
[panRecognizer setDelaysTouchesBegan:NO];
[panRecognizer setDelaysTouchesEnded:NO];
[self.view addGestureRecognizer:panRecognizer];
}

-(void)panHandler:(UIPanGestureRecognizer *)recognizer {
   //gesture hanlding here
   if(recognizer.state == UIGestureRecognizerStateEnded){
      // Do smth here
   }
}

最佳答案

因为可以取消。 来自文档:

Possible ----> Began ----> [Changed] ----> Cancelled
Possible ----> Began ----> [Changed] ----> Ended

https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009279-CH1-DontLinkElementID_2

关于ios - UIPanGestureRecognizer : Why there is no StateEnded every time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016983/

相关文章:

ios - 在 ScrollView 上的 View 上添加约束显示异常

ios - 谷歌地图 SDK 版本 1.5 与 iOS 7 应用程序集成

ios - 使用 UIWebview 和下拉菜单时,ios7 选择器不会换行文本。

ios7 - ios7中什么情况下应用程序不会在设备上有收据

ios - UINavigationBar 上的自定义字体不起作用

ios - 键盘隐藏后 scrollView 没有返回到正确的位置

iphone - 应用程序在屏幕关闭时不播放声音,但仍按应有的方式执行其他操作?

ios - AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

ios - 使用 collectionView(_ :layout:sizeForItemAt:) without calling reloadData()) 调整 UICollectionView 单元格的大小

objective-c - 根据 NSArrayController 选择启用 NSButton