1、事件的传递
b) UIPinchGestureRecognizer(捏合)
c) UIPanGestureRecognizer(平移)
d) UISwipeGestureRecognizer(轻扫)
e) UIRotationGestureRecognizer(旋转)
// 手指单击
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(singleGesture:)];
[self.view addGestureRecognizer:singleTap];
// 手指双击
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(doubleGesture:)];
// 手指轻击次数
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
// 平移手势
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:panGesture];
// 轻扫手势
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
// 手势方向
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeGesture];
其他手势的创建方式和以上差不多,就不一一列举了
从事件发生到其处理的对象,传递要经过特殊的一段过程,当屏幕接触的触摸时,ios将其打包到UIEvent对象中放入活动事件队列中。UIApplication对象从事件队列中取出最前面的事件分发,通常会给事件一个应用程序的主窗口(UIWindow)再由窗口对象发送事件给第一响应者处理。
响应者对象是一个能接收并处理事件的对象。UIResponser是所有响应者对 象的基类。该基类定义了一系列编程接口,不但为事件处理进行服务而且还提 供了通用的响应行为处理
响应者链是一系列已连接的响应者对象、事件或消息在其路径向上进行传递,在其允许上响应者将事件处理的责任传递给高层的下一个响应者。
UIGestureRecognizer类定义了所有手势的基本行为,以下是UIGestureRecognizer子类
a) UITapGestureRecognizer(轻击)b) UIPinchGestureRecognizer(捏合)
c) UIPanGestureRecognizer(平移)
d) UISwipeGestureRecognizer(轻扫)
e) UIRotationGestureRecognizer(旋转)
f) UILongPressGestureRecognizer(长按)
userInteractionEnabled用户交互,默认也为NO.
// 手指单击
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(singleGesture:)];
[self.view addGestureRecognizer:singleTap];
// 手指双击
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(doubleGesture:)];
// 手指轻击次数
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
// 平移手势
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:panGesture];
// 轻扫手势
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
// 手势方向
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeGesture];
其他手势的创建方式和以上差不多,就不一一列举了