更新时间:2023-02-26 21:35:11
为什么不使用滑动手势识别器呢? / p>
UISwipeGestureRecognizer * swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe :)];
UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe :)];
//设置滑动方向。
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
//在WebView上添加滑动手势
[webView addGestureRecognizer:swipeLeft];
[webView addGestureRecognizer:swipeRight];
- (void)handleSwipe :( UISwipeGestureRecognizer *)刷卡{
if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){
NSLog(@Left Swipe) ;
}
if(swipe.direction == UISwipeGestureRecognizerDirectionRight){
NSLog(@Right Swipe);
}
}
I have a WebView in my app.
Because it is a tabbed application I'm not able to add buttons for going back/forward on the website.
I want to go back/forward by swiping. Right swipe from the left side/edge is back… like in Safari browser for iOS.
How can I do it? I think i should use "Screen Edge Pan Gesture Recognizer", right?
Why not just use a swipe gesture recognizer?
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the swipe gesture on WebView
[webView addGestureRecognizer:swipeLeft];
[webView addGestureRecognizer:swipeRight];
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left Swipe");
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Right Swipe");
}
}