简体   繁体   English

iPhone uiwebview初始白视图

[英]iphone uiwebview initial white view

My app's main view has a uiwebview. 我的应用程序的主视图有一个uiwebview。 It is white for a split second before it has time to render the HTML the app generates. 在有时间呈现应用程序生成的HTML之前,它是一秒钟的白色。

Is there a way to make the uiwebview black, or another color, before it renders? 有没有一种方法可以将uiwebview呈现为黑色或其他颜色? The flash of white isn't part of my plan for a smooth visual transition. 白色的闪烁不是我实现平滑视觉过渡的计划的一部分。

Objective-C or MonoTouch answers are fine, I am bi-lingual. Objective-C或MonoTouch的答案很好,我是双语的。

Another thing to try is to make the view transparent: 要尝试的另一件事是使视图透明:

webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;

This causes additional compositing work, however, so you can reset these values to something more friendly for that after your web view loads, in webViewDidFinishLoad: . 但是,这会导致额外的合成工作,因此您可以在webViewDidFinishLoad:加载后在webViewDidFinishLoad:这些值重置为更友好的值。

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    webView.backgroundColor = [UIColor blackColor];
    webView.opaque = YES;
}

One thing you can try is put a UIView with the color you want and position it above the UIWebView with the same width and height. 您可以尝试的一件事是,将具有所需颜色的UIView放置在具有相同宽度和高度的UIWebView上方。 Then in the webViewDidFinishLoad method, set the UIView to hidden. 然后在webViewDidFinishLoad方法中,将UIView设置为隐藏。

I can't comment yet hence the answer. 我无法发表评论,因此给出答案。 @Steve, actually it's possible to do with storyboards. @Steve,实际上可以使用情节提要。

Place a UIView under the UIWebView and: 将UIView放在UIWebView下并:

// Can be set in the storyboard
bottomView.backgroundColor = [UIColor yellowColor];
webview.alpha = 0;

Keep in mind that a lot of page fetch stuff after being loaded via JS so you still can be left with a white page couple seconds after 请记住,许多页面是通过JS加载后获取内容的,因此在几秒钟后仍会留下白页

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    webView.alpha = 1;
}

To add to Steve Madsen's answer (since I can't comment yet). 添加到史蒂夫·马德森(Steve Madsen)的答案中(因为我无法发表评论)。 If you instanced the UIWebView in Interface Builder, you wont be able to set alpha to 0.0, but what you can do is bring up the color picker to set a background color (white, black, gray, it doesnt matter), then set the opacity of that color to zero percent, and that works. 如果在Interface Builder中将UIWebView实例化,则无法将alpha设置为0.0,但是您可以做的是调出颜色选择器以设置背景色(白色,黑色,灰色,没关系),然后设置该颜色的不透明度为零%,并且可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM