- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *recognizer = nil;
//
// 向右划動
//
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
//
// 向左划動 www.2cto.com
//
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
}
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
// TODO:
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// TODO:
}
}
摘自 wangsoko的專欄