zoukankan      html  css  js  c++  java
  • UIKit框架之UIGestureRecognizer

    ---恢复内容开始---

    1.继承链:NSObject

    2.UIGestureRecognizer的子类有以下:

    3.想要使用手势一系列的行为需要遵守 UIGestureRecognizerDelegate协议

    4.初始化手势识别器

        (1)- (instancetype)initWithTarget:(id)target
                            action:(SEL)action
      :为一个对象初始化和分配空间,并设定手势的行为

    5.添加和移除target和行为

        (1)- (void)addTarget:(id)target
               action:(SEL)action
      :为手势识别器对象添加一个target,并设定指定的行为

        (2)- (void)removeTarget:(id)target
                  action:(SEL)action
      :从手势识别器中移除指定的target和指定的action

    6.获取手势的touches和位置

        (1)- (CGPoint)locationInView:(UIView *)view  :返回指定视图被触摸的位置

        (2)- (CGPoint)locationOfTouch:(NSUInteger)touchIndex
                        inView:(UIView *)view
      :触摸点相对于指定视图的位置

        (3)- (NSUInteger)numberOfTouches  :触摸点的数量

    7.获取手势的状态和视图

        (1)@property(nonatomicreadonlyUIGestureRecognizerState state  :获取手势的状态

        (2)@property(nonatomicreadonlyUIView *view  :获取接受手势的视图

        (3)@property(nonatomicgetter=isEnabledBOOL enabled  :手势是否可用

    8.取消和延迟触摸

        (1)@property(nonatomicBOOL cancelsTouchesInView  :取消视图的触摸

        (2)@property(nonatomicBOOL delaysTouchesBegan  :延迟触摸的开始

        (3)@property(nonatomicBOOL delaysTouchesEnded  :延迟触摸的结束

    9.指定两个手势识别器的依赖

        (1)- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer  :只有当别的识别器触发失败的时候才使用该识别

    10.设定委托

        (1)@property(nonatomicweakidUIGestureRecognizerDelegate delegate  :设定指定的委托

    11.子类的方法

        (1)- (void)touchesBegan:(NSSet<UITouch *> *)touches
               withEvent:(UIEvent *)event
      :触摸屏幕时开始执行这个方法

        (2)- (void)touchesMoved:(NSSet<UITouch *> *)touches
               withEvent:(UIEvent *)event
      :触摸移动过程中执行这个方法

        (3)- (void)touchesEnded:(NSSet<UITouch *> *)touches
               withEvent:(UIEvent *)event
      :触摸结束的时候执行这个方法

        (4)- (void)touchesCancelled:(NSSet<UITouch *> *)touches
                   withEvent:(UIEvent *)event
      :当触摸因为意外情况而取消就会执行这个方法

        (5)- (void)reset  :重置手势

        (6)- (void)ignoreTouch:(UITouch *)touch
               forEvent:(UIEvent *)event
      :忽略某个事件的手势

        (7)- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer  :重载这个方法能够执行UIGestureRecognizerDelegate协议里面的方法gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:.

        (8)- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer  :Overridden to indicate that the receiver can prevent the specified gesture recognizer from recognizing its gesture.

        (9)- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer  :重载这个方法来设定接收者不响应指定的手势

        (10)- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer  :重载这个方法来指定接收者应该被要求失败通过指定的手势识别器,Overridden to indicate that the receiver should be required to fail by the specified gesture recognizer.

        (11)- (void)ignorePress:(UIPress *)button
               forEvent:(UIPressesEvent *)event
      :告诉手势识别器忽视按的事件

        (12)- (void)pressesBegan:(NSSet<UIPress *> *)presses
               withEvent:(UIPressesEvent *)event
      :当按钮被按的时候发送事件到接收者

        (13)- (void)pressesChanged:(NSSet<UIPress *> *)presses
                 withEvent:(UIPressesEvent *)event
      :当按钮的压力变化的时候发送事件到接收者

        (14)- (void)pressesEnded:(NSSet<UIPress *> *)presses
               withEvent:(UIPressesEvent *)event
      :当按钮结束按的动作的时候发送事件给接收者

        (15)- (void)pressesCancelled:(NSSet<UIPress *> *)presses
                   withEvent:(UIPressesEvent *)event
      :当按钮的按动作被取消的时候发送事件到接收者

    12.配置不同的手势

        (1)@property(nonatomiccopyNSArray <NSNumber *> *allowedPressTypes  :一组不同按的类型来区分按钮被按

        (2)@property(nonatomiccopyNSArray <NSNumber *> *allowedTouchTypes  :一组不同的触摸类型,用来区分不同的touches

    13.数据类型

        (1)UIGestureRecognizerState类型

    UIGestureRecognizerStatePossible,

    UIGestureRecognizerStateBegan,

    UIGestureRecognizerStateChanged,

    UIGestureRecognizerStateEnded,

    UIGestureRecognizerStateCancelled,

    UIGestureRecognizerStateFailed,

    UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded

    ---恢复内容结束---

  • 相关阅读:
    rosservice call ERROR:Unable to load type ... Have you typed 'make'
    查看ubuntu版本号
    VirtualBox虚拟机 host/guest 拷贝粘贴,共享剪贴板,安装guest additions
    traffic_light_bag_file 数据集 下载链接
    ubuntu linux double tab
    ubuntu linux查看cpu信息
    ubuntu linux查看硬盘使用量
    ubuntu查看nvidia显卡状态
    ibus
    windows7 屏幕亮图胡乱变化
  • 原文地址:https://www.cnblogs.com/lelun/p/5722985.html
Copyright © 2011-2022 走看看