1.模块继承关系:
1.UIButton ->UIControl -> UIView
2.UILabel ->UIview
3.UIImageView ->UIView
4.UITextField ->UIControl
对于@selector为什么可以监听:@selector将监听方法注册到”运行循环“,”运行循环“当按钮点击后,通知视图控制器执行@selector的方法
UIControl的剖析:
1 /______________________________________________________ 2 3 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIControl : UIView 4 5 //1.1设置控件的状态 启用 禁用:一个按钮可不可以点击 6 @property(nonatomic,getter=isEnabled) BOOL enabled; // default is YES. if NO, ignores touch events and subclasses may draw differently 选中 不选中: 7 @property(nonatomic,getter=isSelected) BOOL selected; // default is NO may be used by some subclasses or by application 高亮或者不高亮 8 @property(nonatomic,getter=isHighlighted) BOOL highlighted; // default is NO. this gets set/cleared automatically when touch enters/exits during tracking and cleared on up 1.2设置控件内容的布局 垂直居中方向9 @property(nonatomic) UIControlContentVerticalAlignment contentVerticalAlignment; // how to position content vertically inside control. default is center 水平居中方向 10 @property(nonatomic) UIControlContentHorizontalAlignment contentHorizontalAlignment; // how to position content hozontally inside control. default is center 11 12 @property(nonatomic,readonly) UIControlState state; // could be more than one state (e.g. disabled|selected). synthesized from other flags. 13 @property(nonatomic,readonly,getter=isTracking) BOOL tracking; 14 @property(nonatomic,readonly,getter=isTouchInside) BOOL touchInside; // valid during tracking only 15 16 - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(nullable UIEvent *)event; 17 - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(nullable UIEvent *)event; 18 - (void)endTrackingWithTouch:(nullable UITouch *)touch withEvent:(nullable UIEvent *)event; // touch is sometimes nil if cancelTracking calls through to this. 19 - (void)cancelTrackingWithEvent:(nullable UIEvent *)event; // event may be nil if cancelled for non-event reasons, e.g. removed from window 20 21 // add target/action for particular event. you can call this multiple times and you can specify multiple target/actions for a particular event. 22 // passing in nil as the target goes up the responder chain. The action may optionally include the sender and the event in that order 23 // the action cannot be NULL. Note that the target is not retained. 24 添加或者删除监听方法 - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 25 26 // remove the target/action for a set of events. pass in NULL for the action to remove all actions for that target 27 - (void)removeTarget:(nullable id)target action:(nullable SEL)action forControlEvents:(UIControlEvents)controlEvents; 28 29 // get info about target & actions. this makes it possible to enumerate all target/actions by checking for each event kind 30 - (NSSet *)allTargets; // set may include NSNull to indicate at least one nil target 31 - (UIControlEvents)allControlEvents; // list of all events that have at least one action 32 - (nullable NSArray<NSString *> *)actionsForTarget:(nullable id)target forControlEvent:(UIControlEvents)controlEvent; // single event. returns NSArray of NSString selector names. returns nil if none 33 34 // send the action. the first method is called for the event and is a point at which you can observe or override behavior. it is called repeately by the second. 35 - (void)sendAction:(SEL)action to:(nullable id)target forEvent:(nullable UIEvent *)event; 36 - (void)sendActionsForControlEvents:(UIControlEvents)controlEvents; // send all actions associated with events 37 38 @end 39 40 NS_ASSUME_NONNULL_END
时间: 2024-08-13 03:13:18