Skip to content

Instantly share code, notes, and snippets.

@tzengyuxio
Created July 26, 2011 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzengyuxio/1106515 to your computer and use it in GitHub Desktop.
Save tzengyuxio/1106515 to your computer and use it in GitHub Desktop.
iOS 手勢範例
// 宣告一個 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