@安德烈亞斯Volz的(和其他人想知道如何解決了白色的「閃光」的問題)
首先,添加name-of-loading-image.png
和[email protected]
文件到您的Xcode項目。常規形象應該是320×460,和@2x
形象應該是640×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];
}
這就是我一直這樣做了很長一段時間的方式。但是現在在iOS 8和動態加載屏幕中,沒有name-of-loading-image.png在視圖加載時加載。 – badweasel 2014-10-20 20:09:25