UIWebView loading progress and adjust web page to fit the view page?(UIWebView 加载进度并调整网页以适应视图页面?)
问题描述
我正在使用 UIWebView 加载网页.
I am using UIWebView to load a web page.
有3个问题:
1.UIWebView在加载页面时可以跟踪百分比进度吗?
1.It it possible to track the percentage progress when UIWebView is loading the page?
2.我注意到,当 Safari 加载网页时,URL 文本字段会显示一个蓝色背景进度指示器,告诉用户加载网页的百分比.这是什么技术?
2.I noticed that when Safari loading a web page, the URL textfield displays a blue background progress indicator to tell user the percentage of loading a web page. What is the technology for this?
3.我知道有属性 scalesPageToFit
3.I know there is property scalesPageToFit
scalesPageToFit一个布尔值,用于确定网页是否缩放以适应视图并且用户可以更改比例.
scalesPageToFit A Boolean value determining whether the webpage scales to fit the view and the user can change the scale.
我尝试将其设置为 YES,但它似乎不在公共 API 中,并且我的应用因黑屏而停止,我不确定是什么问题?
I try to set it to YES, but it looks like that it is not in public API and my app stopped with black screen, I am not sure what is wrong?
推荐答案
回答#1)
您可以使用 NSURLConnection 将网页作为 NSData 对象下拉,而不是使用 UIWebView.当您收到来自
Instead of using a UIWebView, you can pull the webpage down as an NSData object using an NSURLConnection. When you get the initial response from your request from
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
网络服务器应返回预期内容大小"的值(应包含在响应中).然后每次接收数据时都会不断调用以下方法:
the webserver should return a value of "expected content size" (which should be included in the response). Then you will keep getting the following method called each time you receive data:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
继续将数据附加到现有的 NSMutableData 对象.然后您可以对照预期的响应大小检查当前数据对象 (NSMutableData.length) 的大小.
Keep appending the data to an existing NSMutableData object. Then you can check the size of your current data object (NSMutableData.length) against the expected response size.
percentage = (myData.length*100)/theResponse.expectedContentSize;
然后您可以使用该百分比更新进度条!当
Then you can update a progress bar with that percentage! When
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
运行,用你的数据调用
[myWebView loadData:myData MIMEType:myMimeType textEncodingName:myEncoding baseURL:baseURL];
它会将您下拉的所有内容加载到您的网络视图中.
and it will load everything you pulled down into your web view.
这篇关于UIWebView 加载进度并调整网页以适应视图页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebView 加载进度并调整网页以适应视图页面?
- URL编码Swift iOS 2022-01-01
- UITextView 内容插图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01