启动图像后,XCode阻止UIWebView闪烁白屏 [英] XCode Prevent UIWebView flashing white screen after Launch Image
问题描述
我是XCode的新手 - 我正在设计一个带有单一视图的应用程序,它只显示一个加载我的jQuery移动网站的UIWebView。
I am fairly new to XCode - I'm designing an app with a single view that just displays a UIWebView that loads my jQuery mobile web site.
我有适用于启动图像的Default.png和Default@2x.png文件。当我在我的测试设备或模拟器上运行应用程序时,它会显示我的启动图像,然后在UIWebView加载第一页时闪烁白屏。
I have the Default.png and Default@2x.png files for the Launch images in place. When I run the app on my test device or in the emulator, it shows my Launch Image, and then flashes a white screen while the UIWebView loads the first page.
我知道我可以改变背景颜色和不透明度,因此它会闪烁不同于白色的颜色,但我想完全阻止闪光。我希望应用程序启动,显示启动图像,并且在第一页完全加载之前不显示UIWebView。帮助?
I know that I can change the background color and opacity so it will flash a different color than white, but I would like to prevent the flash altogether. I would like the app to launch, show the Launch image, and not show the UIWebView until the first page has completely loaded. Help?
推荐答案
@Andreas Volz(还有其他人想知道我是如何解决白色闪光的问题)
@ Andreas Volz (and anyone else wondering how I solved the problem of the white "flash")
首先,添加 name-of-loading-image.png
和加载名称-image@2x.png
文件到你的Xcode项目。常规图像应为320 x 460, @ 2x
图像应为640 x 920。
First, add the name-of-loading-image.png
and name-of-loading-image@2x.png
files to your Xcode project. The regular image should be 320 x 460, and the @2x
image should be 640 x 920.
然后,在我的 ViewController.h
文件中,我添加了以下属性:
Then, in my ViewController.h
file I added these properties:
@property (nonatomic, retain) UIWebView *webView;
@property(nonatomic, strong) UIImageView *loadingImageView;
@end
然后在我的 ViewController.m中
file我添加了这个:
And then in my ViewController.m
file I added this:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController;
@synthesize webView;
@synthesize loadingImageView;
- (void)viewDidLoad
{
[super viewDidLoad];
//**************** Set website URL for UIWebView
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];
//**************** Add Static loading image to prevent white "flash" ****************/
UIImage *loadingImage = [UIImage imageNamed:@"name-of-loading-image.png"];
loadingImageView = [[UIImageView alloc] initWithImage:loadingImage];
loadingImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"name-of-loading-image.png"],
nil];
[self.view addSubview:loadingImageView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Remove loading image from view
[loadingImageView removeFromSuperview];
}
这篇关于启动图像后,XCode阻止UIWebView闪烁白屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!