UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[webView addGestureRecognizer:swipeRight];
[swipeRight release];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[webView addGestureRecognizer:swipeLeft];
[swipeLeft release];
-(void)swipe:(UISwipeGestureRecognizer *)g{
if (g.direction == UISwipeGestureRecognizerDirectionRight) {
[self prevPage];
} else {
[self nextPage];
}
}
UISwipeGestureRecognizer 是UIGestureRecognizer的子类,还有以下几个:
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer