在 iOS 中显示动画 GIF [英] Display animated GIF in iOS

查看:32
本文介绍了在 iOS 中显示动画 GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到使用 iMessage,现在可以发送和显示动画 gif.这是否意味着 Apple 现在支持在应用程序中显示动画 GIF,还是最简单的方法仍然是将图像分成帧然后依次显示?从 iOS 5.1 开始,显示动画 GIF 的最简单方法是什么?

I noticed that with iMessage, animated gifs can now be sent and displayed. Does this mean that Apple is now supporting the display of animated GIFs in an application, or is the easiest method still to split the image in frames and then sequentially show them? What is the easiest way to display an animated GIF as of iOS 5.1?

谢谢!

推荐答案

如果您面向 iOS7 并且已经将图像拆分为多个帧,您可以使用 animatedImageNamed:duration:.

If you are targeting iOS7 and already have the image split into frames you can use animatedImageNamed:duration:.

假设您正在制作一个微调器的动画.将所有框架复制到项目中并按如下方式命名:

Let's say you are animating a spinner. Copy all of your frames into the project and name them as follows:

  • spinner-1.png
  • spinner-2.png
  • spinner-3.png
  • ,

然后通过以下方式创建图像:

Then create the image via:

[UIImage animatedImageNamed:@"spinner-" duration:1.0f];

来自文档:

此方法通过附加一系列数字来加载一系列文件到 name 参数中提供的基本文件名.例如,如果name 参数的内容是image",这个方法会尝试从名称为image0"、image1"的文件中加载图像依此类推,一直到image1024".所有图片包含在动画图像应具有相同的大小和比例.

This method loads a series of files by appending a series of numbers to the base file name provided in the name parameter. For example, if the name parameter had ‘image’ as its contents, this method would attempt to load images from files with the names ‘image0’, ‘image1’ and so on all the way up to ‘image1024’. All images included in the animated image should share the same size and scale.

这篇关于在 iOS 中显示动画 GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆