Set loading gif in UIWebView while it's loading

最后都变了- 提交于 2019-12-08 09:54:28

问题


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.

I know I have to do it in

– webViewDidStartLoad:(UIWebView *)webView

But how do I load the image?


回答1:


try this :

    – 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];

    }

and in webViewDidFinishLoad: method remove it from superview

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

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


来源:https://stackoverflow.com/questions/7144895/set-loading-gif-in-uiwebview-while-its-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!