Created
July 26, 2011 11:49
-
-
Save tzengyuxio/1106562 to your computer and use it in GitHub Desktop.
單點擊與雙點擊同時成立
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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