iOS手势学习笔记
2016-04-14 14:24
447 查看
UIGestureRecognizer介绍
手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性。iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作。
UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(捏合) UIRotationGestureRecognizer(旋转) UITapGestureRecognizer(点按) UILongPressGestureRecognizer(长按) UISwipeGestureRecognizer(轻扫)
另外,可以通过继承 UIGestureRecognizer 类,实现自定义手势(手势识别器类)。
PS:自定义手势时,需要
#import UIKit/UIGestureRecognizerSubclass.h 一般需实现如下方法
- (void)reset; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
//以上方法在分类 UIGestureRecognizer (UIGestureRecognizerProtected) 中声明,更多方法声明请自行查看
UIGestureRecongnizer的继承关系如下
手势状态枚举如下
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { UIGestureRecognizerStatePossible, // 尚未识别是何种手势操作(但可能已经触发了触摸事件),默认状态 UIGestureRecognizerStateBegan, // 手势已经开始,此时已经被识别,但是这个过程中可能发生变化,手势操作尚未完成 UIGestureRecognizerStateChanged, // 手势状态发生转变 UIGestureRecognizerStateEnded, // 手势识别操作完成(此时已经松开手指) UIGestureRecognizerStateCancelled, // 手势被取消,恢复到默认状态 UIGestureRecognizerStateFailed, // 手势识别失败,恢复到默认状态 UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded // 手势识别完成,同UIGestureRecognizerStateEnded };
检测多次轻点
由于ios支持多个点击,点击1下触发一个动作(action1),点击2(action2)下触发一个动作。这些点击之间的是没有联系的。例如你点击了两下屏幕。那么action1就会触发两次,action2就会触发一次。那怎么保证我只想触发一下action2,而不触发action1[singleTap requireGestureRecognizerToFail:doubleTap]
这样就会在action2失败以后,才会执行action1
手势的代理
UIGestureReconginizerDelegate相关文章推荐
- iOS应用内判断推送开发是否打开
- iOS navigationcontroller中的back按钮的隐藏及右滑pop操作整理
- iOS代码获取图片主色调
- ios runtime 工作模式
- iOS常用的一些正则表达式代码举例
- 分享iOS平台弹幕解决方案HJDanmakuDemo
- IOS AutoLayout 遍历修改约束
- iOS开发之应用内检测手机锁屏,解锁状态
- iOS新浪微博分享SDK Check List
- iOS开发之设置navigationBar的背景颜色为无色
- iOS 一套@3x图片兼容所有iOS设备和系统
- iOS开发总结之自定义等高cell03-xib
- FFmpeg在iOS mac 终端上下载
- iOS开发获取系统表情
- iOS runtime运行机制
- iOS编程--AVCapture编程理解--自定义相机
- IOS开发语言OC的基本语法以及结构
- iOS的Target-Action模式传值的最佳方式
- 在 iOS 上捕获视频
- iOS 设置启动图片