1

私は XCode を初めて使用します。jQuery モバイル Web サイトをロードする UIWebView を表示する単一のビューを持つアプリを設計しています。

起動イメージの Default.png および Default@2x.png ファイルが配置されています。テスト デバイスまたはエミュレーターでアプリを実行すると、起動イメージが表示され、UIWebView が最初のページを読み込む間、白い画面が点滅します。

背景色と不透明度を変更して、白とは異なる色で点滅できることは知っていますが、フラッシュを完全に防ぎたいと思います。最初のページが完全に読み込まれるまで、アプリを起動して起動イメージを表示し、UIWebView を表示しないようにしたいと思います。ヘルプ?

4

2 に答える 2

4

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

}
于 2012-07-26T12:48:20.690 に答える
1

webView の読み込みがいつ終了したかを知るには、UIWebViewDelegate プロトコルを実装する必要があります。

viewController の .h ファイルで:

@interface viewController : UIViewController <UIWebViewDelegate>
{
    UIWebView *webView;
}
@end

次に、viewController の .m ファイルに、次のメソッドを追加します。

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    NSLog(@"content loading finished");
    // Display your webView
    [self.view addSubview:webView];

}

viewController の .m で -viewDidLoad メソッドを使用して、引き続き起動イメージを表示できます。webView のコンテンツの読み込みを開始することもできます。

- (void)viewDidLoad {
    [super viewDidLoad];

    // continue to display launch image
    UIImage *launchImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"launchImage.png" ofType:nil ]];
    UIImageView *launchImageView = [[[UIImageView alloc] initWithImage:launchImage] autorelease];
    [self.view addSubview:launchImageView];

    // now setup the base view for the webView controller
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor blueColor];

    // for rotation
    contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    self.view = contentView;

    //create a frame to size and place the web view
    CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
    UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
    self.webView = aWebView;

    //aWebView.scalesPageToFit = YES;
    aWebView.autoresizesSubviews = YES;
    aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

    //set the web view delegates for the web view to be itself
    [aWebView setDelegate:self];

    //determine the path the to the index.html file in the Resources directory
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [aWebView loadRequest:requestObj];
}
于 2012-07-13T22:03:07.153 に答える