美文网首页
UIButton 继承树

UIButton 继承树

作者: i爱吃土豆的猫 | 来源:发表于2021-04-11 19:31 被阅读0次

继承树

UIButton -> UIControl -> UIView -> UIResponder -> NSObject

image.png

NSObject

所有 Objective-C 对象的基类,封装了内存管理、消息的传递机制等底层逻辑。

UIResponder

UIResponder 定义了响应和处理事件的接口。它是 UIApplication 和 UIView 的父类,而 UIView 则是 UIWindow 的父类。

有两种一般事件:

点击事件(Touche Events)
手势事件(Motion Events)
除此之外还有:

远程控制事件(Remote Control Events)
重压事件(Press Events)(iOS 9.0 3D Touch)
点击 事件的主要处理方法有:

touchesBegan:withEvent:
touchesMoved:withEvent:
touchesEnded:withEvent:
touchesCancelled:withEvent:.

UIView

UIView 定义了一个屏幕上的矩形区域,以及管理这个区域内容的接口。UIView 提供了一个基本行为就是为这个矩形区域填充背景色(Background Color)。

UIControl

UIControl 是 UIButton,UISwitch,UITextField 以及 UISegmentedControl 等类的父类。

不要使用 UIControl 的实例,而是写 UIControl 的子类。

UIControl 子类的主要工作就是将 UIResponder 收集到的复杂事件,变成简单的控制事件(UIControl Events)。而为了实现这个过程,UIControl 引入了 Target-Action 机制

typedef NS_OPTIONS(NSUInteger, UIControlEvents) {
    UIControlEventTouchDown                                         = 1 <<  0,      // on all touch downs
    UIControlEventTouchDownRepeat                                   = 1 <<  1,      // on multiple touchdowns (tap count > 1)
    UIControlEventTouchDragInside                                   = 1 <<  2,
    UIControlEventTouchDragOutside                                  = 1 <<  3,
    UIControlEventTouchDragEnter                                    = 1 <<  4,
    UIControlEventTouchDragExit                                     = 1 <<  5,
    UIControlEventTouchUpInside                                     = 1 <<  6,
    UIControlEventTouchUpOutside                                    = 1 <<  7,
    UIControlEventTouchCancel                                       = 1 <<  8,

    UIControlEventValueChanged                                      = 1 << 12,     // sliders, etc.
    UIControlEventPrimaryActionTriggered NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 13,     // semantic action: for buttons, etc.

    UIControlEventEditingDidBegin                                   = 1 << 16,     // UITextField
    UIControlEventEditingChanged                                    = 1 << 17,
    UIControlEventEditingDidEnd                                     = 1 << 18,
    UIControlEventEditingDidEndOnExit                               = 1 << 19,     // 'return key' ending editing

    UIControlEventAllTouchEvents                                    = 0x00000FFF,  // for touch events
    UIControlEventAllEditingEvents                                  = 0x000F0000,  // for UITextField
    UIControlEventApplicationReserved                               = 0x0F000000,  // range available for application use
    UIControlEventSystemReserved                                    = 0xF0000000,  // range reserved for internal framework use
    UIControlEventAllEvents                                         = 0xFFFFFFFF
};

此外,UIControl 还定义了状态 UIControlState。

typedef NS_OPTIONS(NSUInteger, UIControlState) {
    UIControlStateNormal       = 0,
    UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is set
    UIControlStateDisabled     = 1 << 1,
    UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)
    UIControlStateFocused NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 3, // Applicable only when the screen supports focus
    UIControlStateApplication  = 0x00FF0000,              // additional flags available for application use
    UIControlStateReserved     = 0xFF000000               // flags reserved for internal framework use
};

相关文章

网友评论

      本文标题:UIButton 继承树

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