How to Display GIF Image on iPhone UIIMageView

江枫思渺然 提交于 2020-01-12 06:26:07

问题


i have found some ways but they are actually reading frames and applying transition which reduces the quality of animation.. is there any way to display GIF on iPHone application as it is..? Thanks in Advance..


回答1:


Animated GIF won't animate, but if you have a GIF, save each animation as a separate GIF and then setup animationImages array with all those GIFs you just saved:

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"image1.gif"],
                               [UIImage imageNamed:@"image2.gif"],
                               [UIImage imageNamed:@"image3.gif"],
                               [UIImage imageNamed:@"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];



回答2:


use a web view.

    if let path = Bundle.main.path(forResource: "animated", ofType: "gif") {
        let url = URL(fileURLWithPath: path)
        let request = URLRequest.init(url: url)
        webview.loadRequest(request)
    }

this will render your image and animate it as expected.



来源:https://stackoverflow.com/questions/2578624/how-to-display-gif-image-on-iphone-uiimageview

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