在UIWebView加载时设置加载gif [英] Set loading gif in UIWebView while it's loading
本文介绍了在UIWebView加载时设置加载gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种简单的方法来显示自定义加载.gif或其他图像,只要UIWebView仍在加载页面。
I'm searching for an easy method to display a custom loading .gif or another image as long as a UIWebView is still loading the page.
我知道我必须这样做
– webViewDidStartLoad:(UIWebView *)webView
但如何加载图像?
推荐答案
尝试这个:
– webViewDidStartLoad:(UIWebView *)webView {
UIImageView *animatedImages;
NSMutableArray *imageArray;
// Array to hold jpg images
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
// Build array of images, cycling through image names
for (int i = 0; i < IMAGE_COUNT; i++)
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"yourGifImage%d.jpg", i]]];
// Animated images - centered on screen
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,IMG_HEIGHT,IMG_WIDTH)];
animatedImages.center = self.webView.center;
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
// One cycle through all the images takes 1 seconds
animatedImages.animationDuration = 1.0;
// Repeat forever
animatedImages.animationRepeatCount = 0;
animatedImages.tag = 1;
[animatedImages startAnimating];
// Add to webview
[self.webView addSubview:animatedImages];
}
和 webViewDidFinishLoad:
方法将其从superview中删除
and in webViewDidFinishLoad:
method remove it from superview
- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIView * removeAminatingImages = [self.webView viewWithTag:1];
[removeAminatingImages removeFromSuperview];
}
这篇关于在UIWebView加载时设置加载gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文