2010-09-14 34 views
2

我知道'nil'會在動畫結束時清除imageView。但是有沒有辦法在其中一個圖像上結束它?當我在末尾沒有'零'的情況下運行它是一個可愛的錯誤。在xcode中,如何在圖像上停止動畫?

imageView.animationImages = [NSArray arrayWithObjects: 
              [UIImage imageNamed:@"image1.png"], 
              [UIImage imageNamed:@"image2.png"], 
              [UIImage imageNamed:@"image3.png"], 
              [UIImage imageNamed:@"image4.png"], 
              [UIImage imageNamed:@"image5.png"], 
              [UIImage imageNamed:@"image6.png"], 
              [UIImage imageNamed:@"image7.png"], 
              [UIImage imageNamed:@"image8.png"], 
              [UIImage imageNamed:@"image9.png"], 
              [UIImage imageNamed:@"image10.png"], 
            [UIImage imageNamed:@"image0.png"],nil]; 
     imageView.animationDuration = 0.50; 
     [imageView setAnimationRepeatCount: 1]; 
     [imageView startAnimating]; 
+0

實際上,'nil'只是作爲'-arrayWithObjects:'參數的變長列表的終結符。它沒有添加到數組中,事實上,NSArray的實例不可能包含一個零條目。如果你省略'nil',那麼這是一個運行時崩潰,因爲'-arrayWithObjects:'方法有一個未終止的參數列表。 – jlehr 2010-09-15 00:25:15

回答

2

我不認爲有辦法直接做到這一點,但你可以這樣做:

//set your animationImages as stated in the question 
[imageView setAnimationDuration:0.5]; 
[imageView setAnimationRepeatCount:1]; 
[imageView startAnimating]; 
[imageView performSelector:@selector(setImage:) withObject:theFinalImage afterDelay:[imageVIew animationDuration]]; 

基本上,你會通過動畫運行一次,然後更換動畫圖像與最終的靜態圖像。

+0

非常感謝!我最終使用了不同的ImageView作爲結果圖像,但執行選擇器是一個巨大的好處!再次感謝! – Tru99 2010-09-16 17:45:35