码迷,mamicode.com
首页 > 其他好文 > 详细

target action

时间:2014-09-05 03:21:51      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:action   target   触摸   

//为当前视图指定当视图接收到响应事件之后,由target来通过action方法进行响应.

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    //用实例变量存储外界传入的参数,方便在其他方法中使用
    _target = target;
    _action = action;
    _controlEvents = controlEvents;
    NSLog(@"%@",_target);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(UIControlEventTouchDown == _controlEvents)
    {
    //当当前视图接收到触摸事件之后,交由target去处理.
    [_target performSelector:_action withObject:self];
        
    }
    
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (UIControlEventTouchUpInside == _controlEvents) {
        [_target performSelector:_action withObject:self];
    }
}

target action

标签:action   target   触摸   

原文地址:http://qccccc.blog.51cto.com/6004423/1548914

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