我需要加载一个动画Gif图像从网址在UIImageview。
当我使用普通代码时,图像无法加载。
有没有其他方法可以加载Gif动画图像?
发布于 2010-12-08 19:03:25
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];
您可以加载多个gif图像。
您可以使用以下ImageMagick命令拆分gif:
convert +adjoin loading.gif out%d.gif
发布于 2013-03-13 05:01:07
这已经找到了一个公认的答案,但我最近遇到了UIImage+animatedGIF UIImage扩展。它提供了以下类别:
+[UIImage animatedImageWithAnimatedGIFURL:(NSURL *)url]
使您能够简单地:
#import "UIImage+animatedGIF.h"
UIImage* mygif = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:@"http://en.wikipedia.org/wiki/File:Rotating_earth_(large).gif"]];
就像变魔术一样。
发布于 2015-05-07 18:39:40
这是使用Gif Image的最佳解决方案。在你的项目中添加来自Github的SDWebImage。
#import "UIImage+GIF.h"
_imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"thumbnail"];
https://stackoverflow.com/questions/4386675
复制相似问题