前言
iOS中有很多常用的手勢,比如單擊硬爆、雙擊欣舵、縮放、拖拽等等缀磕。接下來缘圈,我為大家來一一介紹一下這些手勢的使用。
正文
單擊
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
singleTap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:singleTap];
雙擊
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
左滑
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwipe];
右滑
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipe];
拖拽
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
[self.view addGestureRecognizer:pan];
縮放
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
[self.view addGestureRecognizer:pinch];
旋轉(zhuǎn)
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
[self.view addGestureRecognizer:rotation];
長按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(processgestureReconizer:)];
longPress.minimumPressDuration = 2.0;
[self.view addGestureRecognizer:longPress];