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