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

查看:96
本文介绍了在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

  • 等。

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

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

Then create the image via:

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

来自文档

此方法通过将一系列数字
附加到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天全站免登陆