2011-12-17 6 views
9

Мне интересно, есть ли вообще анимация UIImage.Можно ли анимировать UIImage?

Я знаю, что UIImageViews можно анимировать, но есть ли способ сделать это прямо в UIImage.

Может быть, с Open GL ES или что-то еще?

Или есть другие способы, которыми можно анимировать MPMediaItemArtwork?

Заранее благодарен!

+0

Какую анимацию вы ищите? Простой перевод и движение? или изменения дисплеев? – richerd

+0

Изменение между несколькими кадрами в основном, вроде как .gif. Как и первый показ image1, затем image2, затем image3 и т. Д. –

ответ

12

Создать UIImageView и установите свойство animationImages в массив UIImage s

Вот пример:

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

1

Проверить UIImage-х +animatedImageWithImages:duration: и +animatedImageNamed:duration:.

От UIImage Class Reference:

Создает и возвращает анимированное изображение из существующего набора изображений.

Этот метод загружает ряд файлов, добавляя серию чисел к имени базового файла, указанному в параметре имени. Например, если в параметре имени было «изображение» в качестве его содержимого, этот метод попытался бы загружать изображения из файлов с именами «image0», «image1» и т. Д. Вплоть до «image1024». Все изображения, включенные в анимированное изображение, должны иметь одинаковый размер и масштаб.

Смежные вопросы