2010-05-26 206 views
0

我在動畫UIImageView中的圖像時遇到了麻煩。動畫UIImageView iPhone

我已經在界面構建器中創建了一個圖像視圖,並將它鏈接到它的iboutlet。這是我的代碼。

@interface Game : UIViewController <UIAccelerometerDelegate>{ 
    IBOutlet UIImageView *diying;  

} @屬性(非原子,保留)的UIImageView *敵營;

在viewDidLoad方法我已經寫了這個代碼

NSArray * imageArray = [[NSArray alloc] initWithObjects: 
         [UIImage imageNamed:@"Die1.gif"], 
         [UIImage imageNamed:@"Die2.gif"], 
         [UIImage imageNamed:@"Die3.gif"], 
         [UIImage imageNamed:@"Die4.gif"], 
         nil]; 

diying.animationImages = imageArray; 
diying.animationDuration = 1.1; 
diying.contentMode = UIViewContentModeBottomLeft; 
[diying startAnimating]; 

[super viewDidLoad]; 

這是我在這裏找到了一個適應:http://icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/

注意:這些.gif文件是簡單的圖像和不動畫。

我做了教程,它工作正常,但我無法弄清楚爲什麼它我的改編不起作用!

回答

0

嘗試加載PNG的,而不是GIF的

而且,你有你的分配的UIImageView?

+0

Gif的很好,當我把gif放在另一個項目(教程)中時,它可以正常工作,並可以自己動畫。 我的UIImageView是在界面生成器中創建的,我還需要手動分配嗎? – 2010-05-26 11:09:00

+0

是的,如果你已經指定了其setter方法;或者可能不是,你必須分配它我認爲。試着去做 – jAmi 2010-05-27 05:46:25