首页 > 其他 > 详细

代理设计模式

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

/**
 *代理设计模式的思想: (只是用代理设计模式)
 
 对于当前视图对象,只负责接收触摸事件,当触摸事件发生之后,通知代理做响应处理,代理如何来处理,视图不关心


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //如果代理实现了对应的协议方法,就去调用, 如果没有实现就不要调用了.
    
    //判断代理是否实现的对应的方法(判断一个对象是否实现了某个方法)
    if ([self.delegate respondsToSelector:@selector(touchViewTouchesBegan:)]) {
        [self.delegate touchViewTouchesBegan:self];
    }
    //触摸开始时,通知代理做相应操作
    

}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
        //触摸移动时(做移动操作),通知代理做相应操作
    if ([self respondsToSelector:@selector(touchViewTouchesMoved:)]) {
            [self.delegate touchViewTouchesMoved:self];
    }


}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
        //触摸结束时,通知代理做相应操作
    if ([self respondsToSelector:@selector(touchViewTouchesEnded:)]) {
        [self.delegate touchViewTouchesEnded:self];
    }
    
}

 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
        //触摸中断时,通知代理做相应操作
    if ([self respondsToSelector:@selector(touchViewTouchesCancelled:)]) {
        [self.delegate touchViewTouchesCancelled:self];
    }
    
}

代理设计模式

原文:http://qccccc.blog.51cto.com/6004423/1548913

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!