iOS UIControl
2015-05-31 11:47
465 查看
提要:
UIControl 是基于Target-Action模式的控件的基类
不应该直接使用
继承自UIView
内容:
UIControl可以实现自定义控件,支持 subclass
Apple Doc给extend
1.针对于特定实践,观察or修改(实现想怎么调用就怎么调用),action消息的分发。
2.提供自定义跟踪行为(想让控件有什么样的track行为)
You may want to extend a
for either of two reasons:
To observe or modify the dispatch of action messages to targets for particular events
To do this, override
evaluate the passed-in selector, target object, or
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:
代码举例
实现控件点击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__);
}
UIControl 是基于Target-Action模式的控件的基类
不应该直接使用
继承自UIView
内容:
UIControl可以实现自定义控件,支持 subclass
Apple Doc给extend
UIControl的建议:
1.针对于特定实践,观察or修改(实现想怎么调用就怎么调用),action消息的分发。
2.提供自定义跟踪行为(想让控件有什么样的track行为)
You may want to extend a
UIControlsubclass
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
UIControlEventsbit
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__);
}
相关文章推荐
- MySQL 中通过使用UNIQUE KEY 来控制字段值不重复的问题.
- hdu4339 Query
- Install: mysql-query-browser
- sdk自带的例子Bluetoothchat运行出错
- ios开发-UIView和UILabel的学习
- hdu 4027 Can you answer these queries?
- '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "AttentionController" nib but the view outlet was not set.'
- UITabBar 蓝色
- Queue::定义
- Android UI测量、布局、绘制过程探究
- static char __setup_str_##unique_id[] __initdata __aligned(1) = str
- Android UI开发: 横向ListView(HorizontalListView)及一个简单相册的完整实现 (附源码下载)
- ERROR JDBCExceptionReporter: Data truncation: Incorrect datetime value
- androidUI那些事(三)
- UITableView
- 通过Jenkins并行完成UI的自动化测试
- UIImage将图片写入本地相册
- 第三章:模块加载系统(requirejs)
- 性能更好的js动画实现方式——requestAnimationFrame
- hdu 5249(set + queue)