2011-10-10 87 views
4

我想要動畫不同版本的PNG;那麼我有三個版本的這個PNG ......一個較暗的版本,一箇中等較暗的版本和一個克萊爾版本。在我的動畫我想做這個類型的動畫IOS:動畫爲.png

黑暗 - >中黑暗 - >克萊爾 - >中黑暗 - >暗 - >中黑暗 - > .....

這可能嗎?

+0

肯定。這是可能的。首先,您可以編寫複雜的算法並根據需要更改圖像亮度。但最簡單的方法是在重複模式下動畫3個圖像:) – beryllium

回答

17

聽起來像是要動畫的UIImageView

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

// load all the frames of our animation 
campFireView.animationImages = [NSArray arrayWithObjects:  
          [UIImage imageNamed:@"campFire01.gif"], 
          [UIImage imageNamed:@"campFire02.gif"], 
          [UIImage imageNamed:@"campFire03.gif"], 
          [UIImage imageNamed:@"campFire04.gif"], 
          [UIImage imageNamed:@"campFire05.gif"], 
          [UIImage imageNamed:@"campFire06.gif"], 
          [UIImage imageNamed:@"campFire07.gif"], 
          [UIImage imageNamed:@"campFire08.gif"], 
          [UIImage imageNamed:@"campFire09.gif"], 
          [UIImage imageNamed:@"campFire10.gif"], 
          [UIImage imageNamed:@"campFire11.gif"], 
          [UIImage imageNamed:@"campFire12.gif"], 
          [UIImage imageNamed:@"campFire13.gif"], 
          [UIImage imageNamed:@"campFire14.gif"], 
          [UIImage imageNamed:@"campFire15.gif"], 
          [UIImage imageNamed:@"campFire16.gif"], 
          [UIImage imageNamed:@"campFire17.gif"], nil]; 

// all frames will execute in 1.75 seconds 
campFireView.animationDuration = 1.75; 
// repeat the annimation forever 
campFireView.animationRepeatCount = 0; 
// start animating 
[campFireView startAnimating]; 
// add the animation view to the main window 
[self.view addSubview:campFireView]; 

http://appsamuck.com/day2.html

+0

以上是不好的建議,你不應該使用UIImageView.animationImages API。請參閱http://stackoverflow.com/questions/8112698/how-to-do-animations-using-images-efficiently-in-ios/8113027#8113027,瞭解在設備上運行時不會崩潰的方法。 – MoDJ