Preloading a UIWebView, avoiding white screen flash(预加载一个UIWebView,避免白屏闪烁)
问题描述
我正在开发一个具有表格导航的应用程序,以最终深入到显示各种信息的 UIWebView
.然而,从 UITableView
的流畅性到 UIWebView
的缓慢性的转变对用户来说是不和谐的,所以我想尽我所能改善这种体验.
I'm working on an app that has table navigation to eventually drill down to UIWebView
that displays various information. However, the transition from the slickness of UITableView
to the slow wonkiness of UIWebView
is jarring for the user so I want to improve that experience however I can.
具体来说,tableViews
和 UIWebView
页面的背景都是黑色背景,但是当我打开 UIWebView
时,它会闪烁空白色大约一秒钟(本地和远程 HTML 文件都是这种情况.)我如何(理想情况下)预加载此过程,或者(至少)使flash"全黑而不是全白?我尝试将视图/webView 的背景设置为黑色,但这似乎没有帮助.
Specifically, the background of both the tableViews
and UIWebView
pages have black backgrounds, but when I open the UIWebView
it flashes empty white for about a second (this is the case for both local and remote HTML files.) How can I (ideally) preload this process, or (at least) make the "flash" be all black rather than all white? I tried making the view / webView's background black but that didn't seem to help.
现在在我的应用程序中,当用户选择一个单元格时,应用程序只会加载 UIWebView
子类并将其推送到导航堆栈上.UIWebView
子类有一个以 & 开头的活动指示器.在 WebViewDidStartLoad
和 WebViewDidFinishLoad 上停止动画,效果很好,但对白色闪光"没有任何帮助.
In my app right now, when a user selects a cell, the app just loads up the UIWebView
subclass and pushes it on the navigation stack. The UIWebView
subclass has an activity indicator that starts & stops animating on WebViewDidStartLoad
and WebViewDidFinishLoad, which works fine, but it doesn't do anything to help the "white flash."
推荐答案
我已经测试过了...我正在发送我用过的两个方法...
I have tested it... I'm sending the two method that I have used...
- (void)viewDidLoad {
[super viewDidLoad]; //objWebView is the outlet of UIWebView
[objWebView loadHTMLString:@"<html><body style="background-color:black;"></body></html>" baseURL:nil];
//the more the delay the errors will be less so within 0.1-0.3 would be fine
[self performSelector:@selector(loadURL:) withObject:nil afterDelay:0.1];
}
-(void)loadURL:(id)sender{
[objWebView stopLoading]; //added this line to stop the previous request
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[objWebView loadRequest:req];
}
这里我在 0.1 秒后执行请求,否则它会像你的情况一样看起来是白色的.或者你可以根据时间给你的延迟时间.干杯:)
here I'm performing the request after 0.1 sec, other wise it will look white as in your case. Or you can give your delay time depending upon the time.. Cheers :)
这篇关于预加载一个UIWebView,避免白屏闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:预加载一个UIWebView,避免白屏闪烁
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01