Ios 动画图像到UIImageView

Ios 动画图像到UIImageView,ios,objective-c,ipad,uiimageview,uiviewanimation,Ios,Objective C,Ipad,Uiimageview,Uiviewanimation,我必须将动画图像设置为UIImageView。 请参见下面的图像的示例,我想在扩展名为.GIF的UIImageView上设置该图像,并将其转换为.PNG格式 我已经尝试了太多的方法去做了。但是没有得到预期的结果。我需要这项技术来创建自己的自定义进度条。 我将此图像分配给我的UIImageView。但这不是动画。。 如果有人有任何想法,请与我分享。您不能在iOS设备中使用.gif图像。不支持GIF动画 相反,您可以将.gif的每一帧添加为.png或.jpg图像,并通过代码为其设置动画 NSArr

我必须将动画图像设置为
UIImageView
。 请参见下面的图像的示例,我想在扩展名为.GIF
UIImageView
上设置该图像,并将其转换为.PNG格式

我已经尝试了太多的方法去做了。但是没有得到预期的结果。我需要这项技术来创建自己的自定义进度条。 我将此图像分配给我的
UIImageView
。但这不是动画。。
如果有人有任何想法,请与我分享。

您不能在iOS设备中使用
.gif
图像。不支持GIF动画

相反,您可以将
.gif
的每一帧添加为
.png
.jpg
图像,并通过代码为其设置动画

NSArray *animateImagesArray = [NSArray arrayWithObjects:myUIImageOne, myUIImageTwo, myUIImageThree, nil];
yourImageView.animationImages      = animateImagesArray;
yourImageView.animationDuration    = 1.0f;
yourImageView.animationRepeatCount = 0; // Repeat forever
[yourImageView startAnimating];

另一个选项是,您可以放置
UIWebView
并在其中加载
gif

如果您想制作动画,则需要拍摄一组具有特定效果的图像,然后在for循环中运行每个图像并赋予动画效果。 此外,如果您仍然想这样做,那么您可以使用OpenGL或cocos2d框架继续前进


但按照iOS标准,只需保持您的UI干净和平面图像。

如果我理解正确,您有一个
gif
文件,并希望将其以动画形式显示在
UIImageView

下面是一个流行的GitHub库,它允许:

使用此
UIImage
类别,您不需要将gif文件解析为多个图像。此库负责gif文件中的单个图像以及为您显示的每个图像的持续时间

NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"];
self.myImageView.image = [UIImage animatedImageWithAnimatedGIFURL:url];

要使用扩展名为.gif的文件,可以使用此第三部分库。这是一个很好的库与演示应用程序

您还可以更改一些代码,使其按照您的需要工作。 如果您有图像数组(.png或其他扩展名),则可以使用APPLE UIImageView:

NSMutableArray* animation = [[NSMutableArray alloc] init];
    for(int i = 0; i<20; i++)
    {
        [animation addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image_%i",i]]];
    }

    UIImageView *player = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [player setAnimationImages:animation];
    [player setAnimationRepeatCount:0]; //0 means infinite loop
    player.animationDuration = 2.f;// time for one hole loop for animation
    [self.view addSubview:player];
    [player startAnimating];//start animation
    [player stopAnimating];//stop animation
并添加委托方法:

- (void)animationDidStart:(CAAnimation *)anim;
 - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag;

一点,这个图像已经是动画类型了…是的,但是我把它转换成了.png,然后我们就可以使用它了。但没有达到我的期望。这很简单。但是对于这种方法,我必须在我的包中添加很多图像。这将增加我的应用程序大小。但这仍然不会像上面的屏幕截图那样平滑。你明白我的真正问题了吗-@MidhunMP@Sarat_Patel:是的,我知道你的问题。另一种方法是放置UIWebView并在其中加载gif图像。请注意:如果使用
CAKeyFrameAnimation
数组应为
CGImage
- (void)animationDidStart:(CAAnimation *)anim;
 - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag;