在UIWebView中向后/向前滑动手势? [英] Swipe gesture for back/forward in UIWebView?

查看:192
本文介绍了在UIWebView中向后/向前滑动手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个WebView。



因为它是一个标签式应用程序,所以我无法在网站上添加用于返回/转发的按钮。 / p>

我想通过滑动返回/前进。右侧滑动从左侧/边缘返回...就像在iOS浏览器浏览器中一样。



我该怎么办?我想我应该使用Screen Edge Pan Gesture Recognizer,对吗?

解决方案

为什么不使用滑动手势识别器呢? / 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");   
} 

}

这篇关于在UIWebView中向后/向前滑动手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆