是否有可能为UIImage制作动画?

Osk*_*son 9 iphone xcode objective-c uiimage ios5

我想知道是否还有动画片UIImage.

我知道UIImageViews有可能动画,但有没有办法直接在一个UIImage.

也许使用Open GL ES或其他什么?

或者还有其他方法可以动画MPMediaItemArtwork吗?

提前致谢!

ric*_*erd 13

创建一个UIImageView并将属性设置animationImagesUIImages 数组

这是一个例子:

NSArray *animationFrames = [NSArray arrayWithObjects:
  [UIImage imageWithName:@"image1.png"],
  [UIImage imageWithName:@"image2.png"], 
  nil];

UIImageView *animatedImageView = [[UIImageView alloc] init];
animatedImageView.animationImages = animationsFrame;
[animatedImageView startAnimating];
Run Code Online (Sandbox Code Playgroud)

如果您的目标是iOS 5,则UIImage无需UIImageView使用即可直接执行此操作

    +(UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration 
Run Code Online (Sandbox Code Playgroud)

例如,

    [UIImage animatedImagesWithImages:animationFrames duration:10];
Run Code Online (Sandbox Code Playgroud)


小智 8

如果您的意思是包含少量图像的动画,请使用以下代码:

   // create the view that will execute our animation
 UIImageView* YourImageView = [[UIImageView alloc] initWithFrame:self.view.frame];

 // load all the frames of our animation
 YourImageView.animationImages = [NSArray arrayWithObjects:    
                             [UIImage imageNamed:@"01.gif"],
                             [UIImage imageNamed:@"02.gif"],
                             [UIImage imageNamed:@"03.gif"],
                             [UIImage imageNamed:@"04.gif"],
                             [UIImage imageNamed:@"05.gif"],
                             [UIImage imageNamed:@"06.gif"],
                             [UIImage imageNamed:@"07.gif"],
                             [UIImage imageNamed:@"08.gif"],
                             [UIImage imageNamed:@"09.gif"],
                             [UIImage imageNamed:@"10.gif"],
                             [UIImage imageNamed:@"11.gif"],
                             [UIImage imageNamed:@"12.gif"],
                             [UIImage imageNamed:@"13.gif"],
                             [UIImage imageNamed:@"14.gif"],
                             [UIImage imageNamed:@"15.gif"],
                             [UIImage imageNamed:@"16.gif"],
                             [UIImage imageNamed:@"17.gif"], nil];

 // all frames will execute in 1.75 seconds
 YourImageView.animationDuration = 1.75;
 // repeat the animation forever
 YourImageView.animationRepeatCount = 0;
 // start animating
 [YourImageView startAnimating];
 // add the animation view to the main window 
 [self.view addSubview:YourImageView];
Run Code Online (Sandbox Code Playgroud)

资源