问题描述
我使用的这是在这里计算器的答案之一,提出了mayoff(罗布Mayoff)的UIImageView + animatedGIF造一流。
I used class made by "mayoff" (Rob Mayoff) "UIImageView+animatedGIF" which was proposed in one of the answers here on stackoverflow. UIImageView+animatedGIF
有了它,我可以在iOS导入已.gif动画中的UIImageView图像。这个类作品完美,但唯一的问题是,.gif注意总是循环。无论我如何将其导出(我从Photoshop图像输出 - 67帧,设置重复,以曾经)。它永远循环中的UIImageView
With it I can import animated .gif images in UIImageView on iOS. This class works flawlessly, but the only problem is that .gif is always looping. No matter how I export it (I am exporting image from photoshop - 67 frames, set repeat to "once") it loops forever in UIImageView.
我进口我.gif注意这些两行:
I am importing my .gif with these two lines:
NSURL *url = [[NSBundle mainBundle] URLForResource:@"Loading" withExtension:@"gif"];
self.loadingImageView.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
很简单,它的作品。
我曾尝试animationRepeatCount属性设置为1,由罗布作为recomended,但没有做的伎俩。此外,我已经试过了的UIImageView的animationImages属性设置为
gifImage.images太,而不是只设置视图的image属性
到gifImage。在这种情况下,.gif注意不动画在所有
very simple and it works.I have tried setting animationRepeatCount property to 1, as recomended by Rob but that didn't do the trick. Also I have tried setting the UIImageView's animationImages property togifImage.images too, instead of just setting the view's image propertyto gifImage. In that case, .gif is not animating at all.
任何想法如何播放.gif注意:只有一次?我能想到的花样繁多的(如设置GIF的最后一帧一段时间后出现,但我第一次尝试简单的东西如果可能的话)。
Any ideas how to play that .gif only once? I can think of many tricks (like setting last frame of the gif to show up after some time but I'd first try something simpler if possible).
推荐答案
我从该项目的测试程序,改变了 viewDidLoad中
方法如下:
I took the test app from that project and changed the viewDidLoad
method to this:
- (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];
}
在应用程序启动,它曾经的动画图像,然后只显示最后一帧。如果我接了一个按钮,发送 [self.dataImageView startAnimating]
,然后点击该按钮运行动画一次,然后再次停在最后一帧。
When the app launches, it animates the image once and then shows just the last frame. If I connect a button that sends [self.dataImageView startAnimating]
, then tapping the button runs the animation one more time, then stops again on the last frame.
请确保你设置你的图像查看了我上面做的方式。请确保您的不可以设置图像视图的图片
属性的动画形象。图像视图的图片
如果你想动画停止属性必须设置为一个非动画图像。
Make sure you're setting your image view up the way I do above. Make sure you are not setting the image view's image
property to the animated image. The image view's image
property must be set to a non-animated image if you want the animation to stop.
这篇关于的UIImageView + animatedGIF总是LOOPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!