2011-12-17 12 views
9

Me pregunto si hay alguna forma de animar un UIImage.¿Es posible animar un UIImage?

Sé que es posible animar UIImageViews pero hay alguna manera de hacerlo directamente en un UIImage.

¿Quizás con Open GL ES o algo así?

¿O hay otras formas de animar un MPMediaItemArtwork?

¡Gracias de antemano!

+0

¿Qué tipo de animación estás buscando? Traducción simple y movimiento? o cambiando las pantallas? – richerd

+0

Cambiando entre varios fotogramas básicamente, algo así como un .gif. Como primer show image1 entonces image2 entonces image3 etc. –

Respuesta

12

Crear un UIImageView y establezca la propiedad de animationImages a una serie de UIImage s

He aquí un ejemplo:

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

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

Si usted está apuntando el IOS 5 Puede hacerlo directamente en UIImage sin la UIImageView usando

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

por ejemplo,

[UIImage animatedImagesWithImages:animationFrames duration:10]; 
8

Si se refiere a la animación con unas pocas imágenes, utilice este código:

// 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

Se puede usar esta.

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

agregue el marco del núcleo de cuarzo también. – alok

1

de Check +animatedImageWithImages:duration: y +animatedImageNamed:duration: UIImage.

De UIImage Class Reference:

crea y devuelve una imagen animada de un conjunto existente de imágenes.

Este método carga una serie de archivos al agregar una serie de números al nombre del archivo base provisto en el parámetro de nombre. Por ejemplo, si el parámetro del nombre tenía 'contenido' como su contenido, este método intentaría cargar imágenes de archivos con los nombres 'imagen0', 'imagen1' y así sucesivamente hasta 'imagen1024'. Todas las imágenes incluidas en la imagen animada deben compartir el mismo tamaño y escala.