Created
July 26, 2011 11:17
-
-
Save tzengyuxio/1106515 to your computer and use it in GitHub Desktop.
iOS 手勢範例
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
// 宣告一個 recognizer, 並加到需要偵測該手勢的 UIView 元件上 | |
- (void)viewDidLoad { | |
UISwipeGestureRecognizer* recognizer; | |
// handleSwipeFrom 是偵測到手勢後,所要呼叫的方法 | |
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)]; | |
// 不同的 Recognizer 有不同的實體變數 | |
// 例如 SwipeGesture 可以指定方向 | |
// 而 TapGesture 則可以指定次數 | |
recognizer.direction = UISwipeGestureRecognizerDirectionUp | |
[self.view addGestureRecognizer:recognizer]; | |
[recognizer release]; | |
} | |
- (void)handleSwipeFrom:(UISwipeGestureRecognizer*)recognizer { | |
// 觸發手勢事件後,在這裡作些事情 | |
// 底下是刪除手勢的方式 | |
[self.view removeGestureRecognizer:recognizer]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment