UIWebView 的取消按钮/触摸
我想知道如果用户不想再在屏幕上显示 WebView 窗口,是否有任何方法可以让用户关闭 WebView 窗口......? 我看了这个帖子,但我不太明白。 如何取消 UIWebView? 谁能给我举个例子吗? 这是我的代码:
CGSize webScreen1;
webScreen1 = [[UIScreen mainScreen] applicationFrame].size;
CGRect webFrame1 = CGRectMake((webScreen1.width/11.0) ,(webScreen1.height/19.0) ,webScreen1.width/1.2,webScreen1.height/1.25);
defaultWebView.frame = webFrame1;
self.defaultWebView = [[UIWebView alloc] initWithFrame:webFrame1];
self.defaultWebView.backgroundColor = [UIColor whiteColor];
self.defaultWebView.scalesPageToFit = YES;
self.defaultWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
defaultWebView.inputView.hidden = YES;
[self.view addSubview: self.defaultWebView];
[self.defaultWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[NSString stringWithFormat:(NSString *)@"%@", @"http://www.google.com"]]]];
谢谢!
I wonderd if there is any way to make the user dismiss the WebView window if he doesn't want it anymore on the screen...?
I looked at this post but i didn't understand it well.
How to cancel a UIWebView?
can anyone give me an example please?
This is the code i have:
CGSize webScreen1;
webScreen1 = [[UIScreen mainScreen] applicationFrame].size;
CGRect webFrame1 = CGRectMake((webScreen1.width/11.0) ,(webScreen1.height/19.0) ,webScreen1.width/1.2,webScreen1.height/1.25);
defaultWebView.frame = webFrame1;
self.defaultWebView = [[UIWebView alloc] initWithFrame:webFrame1];
self.defaultWebView.backgroundColor = [UIColor whiteColor];
self.defaultWebView.scalesPageToFit = YES;
self.defaultWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
defaultWebView.inputView.hidden = YES;
[self.view addSubview: self.defaultWebView];
[self.defaultWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[NSString stringWithFormat:(NSString *)@"%@", @"http://www.google.com"]]]];
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不存在取消 webView 之类的事情,您需要做的就是从父视图中删除
UIWebView
。如果您的UIWebView
是self.view
的子视图,那么您可以提供一个名为Close
的按钮,其行为如下 -这应该从你的观点。
There is no such thing as cancel a webView, what you need to do is remove the
UIWebView
from the parent view. If yourUIWebView
is a subview ofself.view
then you can provide a button namedClose
which behaves like this -This should remove the webview from your view.
...让用户关闭 WebView 窗口的方法...
...way to make the user dismiss the WebView window...
看看我将在您上面附加的帖子中解释发生的情况,您将了解该技术,
UIWebview 是一个查看网页的组件,它可能是 html 或其他类型,
有一种隐藏 webview 的方法是在 webview 的 html 中添加一个操作并在应用程序的代码中 ovveride 请求,
当您单击 UIwebview 上的链接或 ahref 或任何操作时,有一个委托方法会在继续请求之前自动运行
您可以在 html 页面上添加按钮或链接并在此方法上验证请求
例如
要点击的内容
并在委托方法
if ([[[请求 URL] 绝对字符串] isEqualToString:@"http://hideWebView/"]) {
[self.webview setHidden:YES];
返回否;
}
返回是;
在这里,
您 ovveride 请求 http://hideWebView/ 并在委托中搜索此请求,然后隐藏 Web 视图或任何你想做的事
look I will explain what happenes in the post you attached above and you will understand the technique,
the UIWebview is a component which views an web page, it may be html or other types,
there is one way to hide your webview is to add an action in the html of the webview and ovveride the request in the code of your app,
when you click on link or ahref or any action on UIwebview there is a delegate method which automatically runs before continuing with the request
you can add a button or link on the html page and ovveride the request on this method
for example
Thing to click
and in the delegate method
if ([[[request URL] absoluteString] isEqualToString:@"http://hideWebView/"]) {
[self.webview setHidden:YES];
return NO;
}
return YES;
}
here you ovveride the request http://hideWebView/ and in the delegate you searched for this request and then hiddes the web view or anything else you want to do