2011-12-17 93 views
9

我想知道是否有反应动画UIImage是否可以为UIImage设置动画?

我知道UIImageViews可以动画,但有什么办法直接在UIImage

也许与Open GL ES或其他?

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

在此先感谢!

+0

你在找什么样的动画?简单的翻译和运动?或更改显示? – richerd 2011-12-17 13:45:40

+0

基本上在多个帧之间切换,有点像.gif。像首先显示image1然后image2然后image3等 – 2011-12-17 13:47:45

回答

12

创建UIImageViewanimationImages的属性设置为UIImage小号

这里的数组是一个例子:

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

UIImageView *animatedImageView = [[UIImageView alloc] init]; 
animatedImageView.animationImages = animationsFrame; 
[animatedImageView startAnimating]; 

如果您定位的iOS 5,你可以在UIImage直接做这没有UIImageView使用

+(UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration 

例如,

[UIImage animatedImagesWithImages:animationFrames duration:10]; 
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]; 

Source

0

您可以使用此。

arrayOfImages=[[NSMutableArray alloc]init]; 
for(int i=1;i<=54;i++) 
{ 
NSString *[email protected]"haKsequence.png"; 
NSString *changedString= [NSString stringWithFormat:@"%d", i]; 
NSString *stringWithoutSpaces = [nameResources  stringByReplacingOccurrencesOfString:@"K" withString:changedString]; 
[arrayOfImages addObject:(id)[UIImage imageNamed:stringWithoutSpaces].CGImage]; 
} 


self.view.userInteractionEnabled=NO; 
i1.hidden=YES; 
image1=[[UIImageView alloc]init]; 
image1.backgroundColor=[UIColor clearColor]; 
image1.frame = button.frame;//i1 is obshaped buttion 
[self.view addSubview:image1]; 
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"]; 
animation.calculationMode = kCAAnimationDiscrete; 
animation.duration = 1; 
animation.values = arrayOfMonkeyImages; 
[animation setDelegate:self]; 
animation.repeatCount=3; 
[animation setRemovedOnCompletion:YES]; 
[image1.layer addAnimation:animation forKey:@"animation"]; 
+0

以及添加石英核心框架。 – alok 2013-05-08 11:56:02

1

检查的UIImage的+animatedImageWithImages:duration:+animatedImageNamed:duration:

UIImage Class Reference来自:

创建并从现有组图像返回的动画图像。

此方法通过在name参数中提供的基本文件名后附加一系列数字来加载一系列文件。例如,如果名称参数具有“图像”作为其内容,则此方法会尝试从名称为“image0”,“image1”等的文件加载图像直至“image1024”。包含在动画图像中的所有图像应该具有相同的大小和比例。

相关问题