您的位置:首页 > 产品设计 > UI/UE

iOS UIControl

2015-05-31 11:47 465 查看
提要:

UIControl 是基于Target-Action模式的控件的基类

不应该直接使用

继承自UIView

内容:

UIControl可以实现自定义控件,支持 subclass

Apple Doc给extend
UIControl的
建议:


1.针对于特定实践,观察or修改(实现想怎么调用就怎么调用),action消息的分发。

2.提供自定义跟踪行为(想让控件有什么样的track行为)

You may want to extend a
UIControl
subclass
for either of two reasons:

To observe or modify the dispatch of action messages to targets for particular events

To do this, override
sendAction:to:forEvent:
,
evaluate the passed-in selector, target object, or
UIControlEvents
bit
mask, and proceed as required.

To provide custom tracking behavior (for example, to change the highlight appearance)

To do this, override one or all of the following methods:
beginTrackingWithTouch:withEvent:
,
continueTrackingWithTouch:withEvent:
,
endTrackingWithTouch:withEvent:
.

代码举例
实现控件点击3才有消息分发即(方法调用)

- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
if (touchTime == 3) {
touchTime = 0;
if ([target respondsToSelector:action]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[target performSelector:action];
#pragma clang diagnostic pop
}
}
}
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
NSLog(@"%s", __FUNCTION__);
BOOL isBegin = NO;
if (++touchTime < 3) {
isBegin = NO;
} else {
isBegin = YES;
}
return isBegin;
}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
NSLog(@"%s", __FUNCTION__);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: