@ Andreas Volz(还有其他想知道我如何解决白色“闪光”问题的人)
首先,将name-of-loading-image.png
和name-of-loading-image@2x.png
文件添加到您的 Xcode 项目中。常规图像应为 320 x 460,@2x
图像应为 640 x 920。
然后,在我的ViewController.h
文件中,我添加了这些属性:
@property (nonatomic, retain) UIWebView *webView;
@property(nonatomic, strong) UIImageView *loadingImageView;
@end
然后在我的ViewController.m
文件中我添加了这个:
#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];
}