zoukankan      html  css  js  c++  java
  • IOS开发UI篇—gesture详解(二)

    与其他用户界面控件交互

    UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用于手势识别重叠的默认动作的控制,其中包括:

    • 一根手指单击动作:UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl. 
    • 一根手指擦碰动作:UISlider
    • 一根手指拖动动作:UISwitch

      包含多点触摸的事件

    在iOS中,touch是指一根手指在屏幕上滑动、移动.而手势是指有一根或多根手指,它的类是UITouch对象.多点触摸事件是UIEventTypeTouches

     

    当发生触摸时,会触发下列方法:

    • touchesBegan:withEvent :触摸屏幕时发生
    • touchesMoved:withEvent :手指在屏幕上移动时发生
    • touchesEnded:withEvent :触摸结束时发生,即手指离开屏幕时
    • touchesCancelled:withEvent :触摸被系统取消时发生,如有电话时,该触摸会被取消

     

    改变默认的事件传递顺序

    你可以通过改变UIGestureRecognizer子类的属性来改变默认的事件传递

    • @property(nonatomic) BOOL delaysTouchesBegan;         // default is NO.  causes all touch events to be delivered to the target view only after this gesture has failed recognition. set to YES to prevent views from processing any touches that may be recognized as part of this gesture
    • @property(nonatomic) BOOL delaysTouchesEnded;         // default is YES. causes touchesEnded events to be delivered to the target view only after this gesture has failed recognition. this ensures that a touch that is part of the gesture can be cancelled if the gesture is recognized

    如果一个gesture recognizer检测到了一个不属于它的touch,它将手势直接发送给它的view,此时会调用ignoreTouch:forEvent: 方法直接传递给view.

    创建自定义gesture recognizer步骤

    • 创建UIGestureRecognizer的子类
    • #import <UIKit/UIGestureRecognizerSubclass.h>
    • 在子类冲重载下列方法
    1.- (void)reset;
    2.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    3.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
    4.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    5.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
  • 相关阅读:
    windows下操作linux虚拟机映射网络驱动器中文件提示chmod权限不足解决方案
    Centos 更改MySQL5.7数据库目录位置
    MySQL语句增加字段,修改字段名,修改类型,修改默认值
    [MySQL]MySQL数据库中如何查询分组后每组中的最后一条记录?
    ROW_NUMBER()函数使用详解
    【转】mysql 存储过程的示例
    简简单单储存过程——循环一个select结果集
    mysql存储过程demo
    mysql日期加一个天数获得新的日期
    使用SyncNavigator轻松实现数据库异地同步、断点续传、异构同步
  • 原文地址:https://www.cnblogs.com/iosblogx/p/4474313.html
Copyright © 2011-2022 走看看