美文网首页
事件响应与手势识别

事件响应与手势识别

作者: lsh_01 | 来源:发表于2019-02-22 19:57 被阅读0次

    本文参考:https://blog.csdn.net/woaihuangrong/article/details/52972913

    以下是简要摘抄内容

    在不考虑内部实现机制的情况下,我们使用三种方式来处理IOS手势:

    1. Gesture Recongnizers — UIGestureRecognizer 及其子类
    2. touches 响应 — touchesBegan、touchesEnd..等
    3. Target-Action 机制 — UIControl及其子类

    注意:
    Apple对于UIControl的一些子类优先于Gesture Recongnizer识别的解释,这一点不适用于UIControl本身和除列表中给出的子类以外的子类

    In iOS 6.0 and later, default control actions prevent overlapping gesture
    recognizer behavior. For example, the default action for a button is a 
    single tap. If you have a single tap gesture recognizer attached to a 
    button’s parent view, and the user taps the button, then the button’s 
    action method receives the touch event instead of the gesture recognizer. 
    This applies only to gesture recognition that overlaps the default action 
    for a control, which includes: 
    * A single finger single tap on a UIButton, UISwitch, UIStepper, 
    UISegmentedControl, and UIPageControl. 
    * A single finger swipe on the knob of a UISlider, in a direction parallel 
    to the slider. 
    * A single finger pan gesture on the knob of a UISwitch, in a direction 
    parallel to the switch.
    

    建议:

    1. UIGestureRecognizer 和 UITouch 都使用HitTest机制来寻找响应控件,hitest机制是一切冲突的基础
    2. 避免同时使用多套手势识别机制,在必须使用的时候,记得考虑冲突
    3. gesture recognizer 不受响应链影响,因为它的优先级高
    4. 尽量不要直接使用UIControl

    相关文章

      网友评论

          本文标题:事件响应与手势识别

          本文链接:https://www.haomeiwen.com/subject/whlyyqtx.html