触摸
//如果想让UIView实现出触摸方法的话,咱们需要重写与touch有关的方法
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
NSLog(@"开始触摸");
// 1. UITouch表示触摸屏幕的一根手指
UITouch*touch = [touches anyObject];
// 2.获取触摸屏幕时的坐标
CGPointstartPoint = [touch locationInView:self];
// 3.打印坐标
NSLog(@"%@",NSStringFromCGPoint(startPoint))
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
NSLog(@"正在摸");
self.backgroundColor= [UIColorcolorWithRed:arc4random()%256/256.0green:arc4random()%256/256.0blue:arc4random()%256/256.0alpha:1];
UITouch*moveTouch = [touches anyObject];
CGPointmovePoint = [moveTouch locationInView:self];
NSLog(@"%@",NSStringFromCGPoint(movePoint));
}
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event{
NSLog(@"不摸了");
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
NSLog(@"摸完了");
}
响应者链
//响应者链多个响应者组成的链
//首先执行检测过程,信息先从UIApplication->Appdelegate->UIWindow->Controller->UIView->其子类(确认在哪个视图上)
//响应过程
//先从View的子类里面寻找有没有事件实现的方法,如果有,事件执行,响应者链完后,如果没有就一层一层往上找,最后找到UIApplication,如果再没有就丢弃