每次启动时 UIWebView 白屏,同时预加载所有选项卡 [英] UIWebView white screen on every launch while preloading all tabs
问题描述
在我提出我的问题之前,我想提一下我尝试寻找解决方案此处 和 此处.
我正在创建一个混合应用程序,它使用本机 UIWebView
来呈现响应式设计的 Web 应用程序.以下是问题描述:
1. 我有一个 UITabBarController
.
2. 每个标签都有一个UIWebView
.
3. 我必须预加载所有标签.
4. 我正在显示 UIActivityIndicator
直到内容加载到第一个选项卡上.
5. 白屏出现约8-10秒,然后开始出现内容.
我会很高兴看到这个时间变成2-4 秒.
Before I present my issue, I want to mention that I tried looking for solutions here and here.
I am creating a hybrid application which uses native UIWebView
for rendering the responsive designed web application. Following is the issue description :
1. I have a UITabBarController
.
2. Each of the tab has a UIWebView
.
3. I have to preload all tabs.
4. I am showing a UIActivityIndicator
till the content loads on the first tab.
5. White screen appears for about 8-10 seconds and then the content starts to appear.
I will be happy to see this time become 2-4 seconds.
以下是我的实现:
[self performSelectorOnMainThread:@selector(loadAllTabs) withObject:nil waitUntilDone:YES];
-(void) loadAllTabs
{
for(UIViewController * viewController in self.viewControllers){
if(![[NSUserDefaults standardUserDefaults]boolForKey:@"isSessionExpired"])
{
if((int)[self.viewControllers indexOfObject:viewController] != 4)
{
viewController.tabBarItem.tag = (int)[[self viewControllers] indexOfObject:viewController];
[viewController view];
}
}
}
}
在 WebView 控制器的 viewDidLoad
中,我有:
In WebView controller's viewDidLoad
I have :
[_tgWebView loadRequest:[NSURLRequest requestWithURL:homeURL]];
我很期待suppressesIncrementalRendering,但由于我正在预加载所有选项卡,因此这不起作用.由于我的应用支持 iOS 7+,因此 WKWebView 不能在这里应用.
我还想到了增加启动图像的持续时间,但了解到这不是一个好习惯.
这可以使用 GCD 实现吗?
请指出我的实现中的缺陷,以便我的应用程序获得更好的性能.
I was looking forward to suppressesIncrementalRendering, but since I am preloading all tabs, this does not work.
Since my app supports iOS 7+, thus WKWebView can't be applied here.
I also thought of increasing the launch image duration but learned that is won't be a good practice.
Can this be implemented using GCD?
Please bring out the pitfalls in my implementations so that my application makes better performance.
推荐答案
这篇 帖子让我开心.我现在为此使用 NSNotificationCenter
.
这篇关于每次启动时 UIWebView 白屏,同时预加载所有选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!