2011-08-22 116 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