0

我试图在加载 UIWebView 时将 UIImageView 用作动画,并在加载完成后删除该视图。但是,当 webview 开始和停止加载时,我无法让它开始/停止动画。代码片段:

@synthesize webView; //UIWebView
@synthesize loadView; //UIImageView

- (void)viewDidLoad {
    // ...

    loadView = [[UIImageView alloc] initWithFrame:[self.view bounds]];
    [loadView setAnimationImages:[NSArray arrayWithObjects:    
                                    [UIImage imageNamed:@"image1.png"],
                                    [UIImage imageNamed:@"image2.png"],
                                    [UIImage imageNamed:@"image3.png"],
                                    nil]];
    [loadView setTag:1];
    [loadView setAnimationDuration:1.0f];
    [loadView setAnimationRepeatCount:0];
    [self.view addSubview:loadView];

    [webView loadRequest:request]; //request is defined somewhere else
}


- (void)webViewDidStartLoad:(UIWebView *)curWebView {
    [loadView startAnimating];
}


- (void)webViewDidFinishLoad:(UIWebView *)curWebView {  
    [loadView removeFromSuperview];
}

- (void)webView:(UIWebView *)curWebView didFailLoadWithError:(NSError *)error {
    [loadView stopAnimating];
    // ... Code to show reload button
}

如果我打电话[loadView startAnimating]viewDidLoad它会动画,但[loadView stopAnimating]仍然webView:didFailLoadWithError无法正常工作。否则,laodView 只显示一个空白的白屏。

4

2 回答 2

0

尝试编写一个带有微调器的本地网页(动画 gif?),加载它并设置它运行,然后在它制作动画时,在后面加载你的远程页面。

于 2013-06-29T00:07:16.470 回答
0

在接口中设置UIWebViewDelegate协议。你有没有设置delegate在文件UIWebView中。XiB

于 2013-06-29T14:17:18.410 回答