码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UIControl

时间:2015-05-31 12:27:54      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:ios   uicontrol   

提要:

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:

代码举例

实现控件点击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__);

}





iOS UIControl

标签:ios   uicontrol   

原文地址:http://blog.csdn.net/forwardto9/article/details/46287365

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!