zoukankan      html  css  js  c++  java
  • iOS开发之手势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;
    
     
  • 相关阅读:
    IDEA远程仓库版本回滚
    智能风控平台核心之风控决策引擎(三)
    智能风控平台核心之风控决策引擎(一)
    深入理解Oracle的imp/exp 和各版本之间的规则
    oracle忘记用户密码
    Windows下使用cmd启动Oracle EM和sql命令使用+主机身份认证
    jsp调用javabean出现错误HTTP Status 500
    jsp查询页面和结果页面在同一页面显示和交互
    javabean+servlet+jsp程序_个人辛苦探索
    用Eclipse 开发Dynamic Web Project应用程序 【转】
  • 原文地址:https://www.cnblogs.com/salam/p/iOS_gesture2.html
Copyright © 2011-2022 走看看