UIButton 继承树

继承树

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

UIButton 继承树_第1张图片
UIKit

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:.

iOS 3.0 引入了 手势 事件,特别是摇一摇。

iOS 4.0 增加了远程控制事件,包括控制中心和耳机线控:

UIButton 继承树_第2张图片
iOS 控制中心

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

UIButton 将 UIResponder 接受的 Events 处理成简单事件。

你可能感兴趣的:(UIButton 继承树)