2011-08-22 71 views
0

我正在寻找一种简单的方法来显示自定义加载.gif或其他图像,只要UIWebView仍在加载页面。在UIWebView中加载gif时加载

我知道我必须这样做,在

– webViewDidStartLoad:(UIWebView *)webView 

但是我怎么加载图像?

+1

到底是什么GIF删除它,因为你可以使用一个UIActivityView? –

回答

2

试试这个:

– 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:方法从上海华

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

    UIView * removeAminatingImages = [self.webView viewWithTag:1]; 
    [removeAminatingImages removeFromSuperview]; 
} 
+0

这是一个有趣的动画图像实现,但我认为更适合的是UIActivityView – Daniel

+0

你能告诉我为什么图像以.lpg结尾,并且我只是将我的gif的所有图像作为PNG? – spankmaster79

+0

@spankmaster它只是输入错误我编辑了它 – Gyani