UIImageView+animatedGIF always LOOPS(UIImageView+animatedGIF 总是 LOOPS)
问题描述
我使用了由mayoff"(Rob Mayoff)UIImageView+animatedGIF"制作的类,这是在 stackoverflow 上的答案之一中提出的.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 上的 UIImageView 中导入动画 .gif 图像.这个类完美无缺,但唯一的问题是 .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]];
非常简单,而且很有效.我尝试按照 Rob 的建议将 animationRepeatCount 属性设置为 1,但这并没有成功.我也尝试将 UIImageView 的 animationImages 属性设置为gifImage.images 也是,而不仅仅是设置视图的图像属性到 gif 图像.在这种情况下,.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 to gifImage.images too, instead of just setting the view's image property to 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.
确保按照我上面的方式设置图像视图.确保您不将图像视图的 image
属性设置为动画图像.如果要停止动画,则必须将图像视图的 image
属性设置为非动画图像.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIImageView+animatedGIF 总是 LOOPS
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01