温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

代理设计模式

发布时间:2020-06-17 19:14:51 来源:网络 阅读:193 作者:缘起愿落 栏目:开发技术

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


- (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];
    }
    
}

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI