UIImageView + animatedGIF总是LOOPS

jov*_*vic 6 animation gif uiimageview ios

我使用了"mayoff"(Rob Mayoff)制作的"UIImageView + animatedGIF"类,这是在stackoverflow的答案之一中提出的.的UIImageView + animatedGIF

有了它,我可以在iOS上的UIImageView中导入动画.gif图像.这个类完美无缺,但唯一的问题是.gif总是循环.无论我如何导出它(我从photoshop导出图像 - 67帧,将重复设置为"一次")它在UIImageView中永远循环.

我用这两行导入我的.gif文件:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Loading" withExtension:@"gif"];
self.loadingImageView.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
Run Code Online (Sandbox Code Playgroud)

很简单,它的工作原理.我已经尝试将animationRepeatCount属性设置为1,正如Rob推荐的那样但是没有做到这一点.此外,我也尝试将UIImageView的animationImages属性设置为gifImage.images,而不是仅将视图的image属性设置为gifImage.在这种情况下,.gif根本不是动画.

任何想法如何只玩一次.gif?我可以想到许多技巧(比如将gif的最后一帧设置在一段时间之后出现,但如果可能的话,我会首先尝试更简单的方法).

rob*_*off 18

我从该项目中获取了测试应用程序并将viewDidLoad方法更改为:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"];
    UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
    self.dataImageView.animationImages = testImage.images;
    self.dataImageView.animationDuration = testImage.duration;
    self.dataImageView.animationRepeatCount = 1;
    self.dataImageView.image = testImage.images.lastObject;
    [self.dataImageView startAnimating];
}
Run Code Online (Sandbox Code Playgroud)

当应用程序启动时,它会为图像设置动画一次,然后显示最后一帧.如果我连接发送的按钮[self.dataImageView startAnimating],则点击该按钮再次运行动画,然后在最后一帧再次停止.

确保您按照我上面的方式设置图像视图.确保将图像视图的image属性设置为动画图像.image如果希望动画停止,则必须将图像视图的属性设置为非动画图像.