我在我的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;
}
但有时,虽然我的网页的部分之间的变化,出现了第二次的启动画面,并再次隐藏。
这是怎么发生的?我可以避免它吗?
有时,当您从UIWebView导航网站时,当前加载被取消。尝试实现 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误方法来检查它是否是错误情况。 –
当你改变网页视图时,可能会发生这种情况,可能会开始加载一些数据.. :) – Rashad
你是什么意思“改变我的网页的部分”? – heximal