2012-07-05 38 views
0

我iphone的初學者,我在陣列中的所有圖像,但如何顯示一個接一個,當我在一個循環中執行陣列..如何在陣列中一個一個地顯示圖像?

NSArray *images = [[NSArray arrayWithObjects: 
         [UIImage imageNamed:@"1.png"], 
         [UIImage imageNamed:@"2.png"], 
         [UIImage imageNamed:@"3.png"], 
         [UIImage imageNamed:@"4.png"], 
         nil] retain]; 


int i=0; 
    int width = 0; 
    int height = 0; 
    for (NSString *imageName in images) 
    { 
     //NSTimer *timer=[[NSTimer alloc]init]; 
     UIImage *image = [images objectAtIndex:i]; 
     //UIImage *image = [UIImage imageNamed:imageName]; 
     animalphoto = [[UIImageView alloc] initWithImage:image]; 
     animalphoto.contentMode = UIViewContentModeScaleAspectFit; 
     animalphoto.clipsToBounds = YES; 



     animalphoto.animationDuration=5.0; 
     animalphoto.animationRepeatCount=0; 

     animalphoto.frame = CGRectMake(animalphoto.frame.size.width * i++, 0, animalphoto.frame.size.width, animalphoto.frame.size.height); 


     width = animalphoto.frame.size.width; 
     height = animalphoto.frame.size.height; 
     NSLog(@"print:%@",image); 
     [animalphoto release]; 
    } 


} 

給出任何建議和示例代碼,這是適用於我們的代碼..

+0

使用此方法: 'imgView.animationImages = images;' – Dhruv 2012-07-05 11:13:49

回答

0

你需要使用UIImageView's對象animationImages設置UIImage陣列
設置animationRepeatCount
設置animationDuration
然後調用[imageView startAnimating];開始日Ë動畫

1

而不是把一個圖像的圖像只是把整個陣列的imgview.animationImages =圖像,而不在for循環

更多參考訪問this網站。

相關問題