IOS-UI高级 事件的响应和手势识别器

1、事件的传递

从事件发生到其处理的对象,传递要经过特殊的一段过程,当屏幕接触的触摸时,ios将其打包到UIEvent对象中放入活动事件队列中。UIApplication对象从事件队列中取出最前面的事件分发,通常会给事件一个应用程序的主窗口(UIWindow)再由窗口对象发送事件给第一响应者处理。


2、事件响应者链的基本概念

响应者对象是一个能接收并处理事件的对象。UIResponser是所有响应者对 象的基类。该基类定义了一系列编程接口,不但为事件处理进行服务而且还提 供了通用的响应行为处理


3、响应者链

响应者链是一系列已连接的响应者对象、事件或消息在其路径向上进行传递,在其允许上响应者将事件处理的责任传递给高层的下一个响应者。


4、手势识别器(UIGestureRecognizer)

UIGestureRecognizer类定义了所有手势的基本行为,以下是UIGestureRecognizer子类

a) UITapGestureRecognizer(轻击) 
b) UIPinchGestureRecognizer(捏合) 
c) UIPanGestureRecognizer(平移) 
d) UISwipeGestureRecognizer(轻扫) 
e) UIRotationGestureRecognizer(旋转) 

f) UILongPressGestureRecognizer(长按)


注:要实现多指点击时,需打开multipleTouchEnabled属性,默认为NO;

    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];
     其他手势的创建方式和以上差不多,就不一一列举了 微笑
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值