UIGestureRecognizer基类是一个抽象类,我们主要是使用它的子类(名字包含链接,可以点击跳到ios Developer library,看官方文档):
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer
从名字上我们就能知道, Tap(点击)、Pinch(捏合)、Rotation(旋转)、Swipe(滑动,快速移动,是用于监测滑动的方向的)、Pan (拖移,慢速移动,是用于监测偏移的量的)以及 LongPress(长按)。
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[self.view addGestureRecognizer:gesture];
gesture.numberOfTapsRequired=1;
gesture.numberOfTouchesRequired=1;
}
-(void)tapClick:(UITapGestureRecognizer *)gesture{
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event //手指触摸屏幕时报告UITouchPhaseBegan事件
{
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event //在手指在屏幕上移动时报告UITouchPhaseMoved事件
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event //在手指离开屏幕时报告UITouchPhaseEnded事件
{
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event //在因接听电话或其他因素导致取消触摸时报告
{
}