@ 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];
}