2014-01-15 53 views
0

我在我的ios应用程序中加载了一个网页。当它加载时,我会显示一个本地图像以避免一段时间的黑屏。加载uiwebview时的背景图像ios有时会显示

我在viewDidLoad中使用此代码:

[myWebView setDelegate:self]; 
theLoadingImageView = [[UIImageView alloc] initWithFrame:myWebView.frame]; 


if([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone){ 

    theLoadingImageView.image = [UIImage imageNamed:@"splash_iphone.png"]; 

} 
else{ 

    theLoadingImageView.image = [UIImage imageNamed:@"splash_ipad.png"]; 

} 





self.logoApp = theLoadingImageView; 
[myWebView addSubview:theLoadingImageView]; 

和代表补充说:

-(void)webViewDidStartLoad:(UIWebView *)myWebView { 
    NSLog(@"start"); 
    theLoadingImageView.hidden = NO; 
} 

-(void)webViewDidFinishLoad:(UIWebView *)myWebView { 
    NSLog(@"finish"); 
    theLoadingImageView.hidden = YES; 
} 

但有时,虽然我的网页的部分之间的变化,出现了第二次的启动画面,并再次隐藏。

这是怎么发生的?我可以避免它吗?

+0

有时,当您从UIWebView导航网站时,当前加载被取消。尝试实现 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误方法来检查它是否是错误情况。 –

+0

当你改变网页视图时,可能会发生这种情况,可能会开始加载一些数据.. :) – Rashad

+0

你是什么意思“改变我的网页的部分”? – heximal

回答

1

UIWebView重新命令它的子视图是完全可能的(它毕竟只是一个带子视图的UIScrollView)。您应该尝试拨打:

-(void)webViewDidStartLoad:(UIWebView *)myWebView { 
    NSLog(@"start"); 
    theLoadingImageView.hidden = NO; 
    [myWebView bringSubviewToFront:theLoadingImageView]; 
} 
+0

它只是在加载一个确定的“页面”而不是其他页面时发生。我会尝试你的代码,我会告诉你什么发生。 – Biribu

+0

有没有可能一旦网页第一次加载,它会一直设置图像背景或隐藏或删除或类似的东西? – Biribu

+0

据我所知,它不会改变您创建的UIImageView的图像或可见性状态 - 但Web视图可能会从它的层次结构中删除它,或者像我之前所说的那样更改子视图索引。你应该在不同的点登录myWebView.subviews,看看你的视图在子视图堆栈 –