Skip to content

Instantly share code, notes, and snippets.

@tzengyuxio
Created July 26, 2011 11:49
Show Gist options
  • Save tzengyuxio/1106562 to your computer and use it in GitHub Desktop.
Save tzengyuxio/1106562 to your computer and use it in GitHub Desktop.
單點擊與雙點擊同時成立
- (void)viewDidLoad {
// 單擊的 Recognizer
UITapGestureRecognizer* singleRecognizer;
singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
singleTapRecognizer.numberOfTapsRequired = 1; // 單擊
[self.view addGestureRecognizer:singleRecognizer];
// 雙擊的 Recognizer
UITapGestureRecognizer* double;
doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapFrom)];
doubleTapRecognizer.numberOfTapsRequired = 2; // 雙擊
[self.view addGestureRecognizer:doubleRecognizer];
// 關鍵在這一行,如果雙擊確定偵測失敗才會觸發單擊
[singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
[singleRecognizer release];
[doubleRecognizer release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment