1、手勢種類ui
- UITapGestureRecognizer 點擊
- UIPinchGestureRecognizer 二指往內或往外撥動
- UIRotationGestureRecognizer 旋轉
- UISwipeGestureRecognizer 滑動,快速移動
- UIPanGestureRecognizer 拖移,慢速移動
- UILongPressGestureRecognizer 長按
2、事件spa
一、單擊
UITapGestureRecognizer* singleRecognizer;
singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSingleTapFrom)];
singleTapRecognizer.numberOfTapsRequired = 1; // 單擊
[self.view addGestureRecognizer:singleRecognizer];
二、雙擊
// 雙擊的 Recognizer
UITapGestureRecognizer* double;
doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleDoubleTapFrom)];
doubleTapRecognizer.numberOfTapsRequired = 2; // 雙擊
[self.view addGestureRecognizer:doubleRecognizer];
// 關鍵在這一行,若是雙擊肯定偵測失敗才會觸發單擊事件
[singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
三、二指往內或往外撥動
UIPinchGestureRecognizer *twoFingerPinch =[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[self.view addGestureRecognizer:twoFingerPinch];
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"Pinch scale: %f", recognizer.scale);
}
四、旋轉
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[rotationRecognizer setDelegate:self];
[self.view addGestureRecognizer:rotationRecognizer];