1。当在UIView中使用UITouch时,重写方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
中使用UITouch *touch=[touches anyObject];获取事件是可以的,
但当类继承自UIViewController时,
则要使用UITouch *touch=[[event allTouches] anyObject];来获取
至于要从UITouch中获取什么信息,你可以使用
NSLog(@"UITouch Info:%@",touch);在Console中查看。
2.在模拟器中要调试多点触摸可以:
鼠标放在模拟器上,按住Option就出来2个点了,然后可以鼠标来调试了,
前提要设置 UIView 的 self.view.multipleTouchEnabled = YES;(支持多点触摸)
以下是多点触摸获取信息方法:
NSSet *allTouches = [event allTouches];
//[allTouches count]获得当前touch的是否是多触摸,如果 [allTouches count] == 1就不是多触摸。
UITouch *touch0 = [[allTouches allObjects] objectAtIndex:0];
UITouch *touch1 = [[allTouches allObjects] objectAtIndex:1];