2013-04-04 23 views
4

在Xcode我有2個按鈕:開始停止UIImageView stopAnimation

當您單擊開始startClick被調用,當你點擊停止stopClick被調用。

當您單擊開始 UIImageView圖像將閃爍來自NSArray的不同圖像。當您點擊停止時,它會停止,但我希望它停止在當我點擊停止時顯示的圖像上。目前它只是停止並消失...有什麼幫助?

繼承人的部分代碼:

- (IBAction)startClick:(id)sender { 

    color.animationImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed: @"img1.png"], 
          [UIImage imageNamed: @"img2.png"], 
          [UIImage imageNamed: @"img3.png"], 
          [UIImage imageNamed: @"img4.png"],nil];  

    [color setAnimationRepeatCount: 0]; 
    color.animationDuration = 1; 
    [color startAnimating]; 
} 

- (IBAction)stopClick:(id)sender { 
    [color stopAnimating]; 

    //What code do i put here to display the last image? (as i clicked stop). 

} 

我也想補充如果,如果顯示的顏色是img1.png然後statments做到這一點......如果它img2.png做到這一點。 ..

+0

把正確的標題...這是很好的程序員其他:) – iPatel 2013-04-04 15:16:05

+0

@ user125697我沒加C++標籤.... – 2013-04-04 15:17:47

+0

其在的。 m類 – user2245512 2013-04-04 15:17:59

回答

1

此代碼將暫停動畫:

color.frame = [[color.layer presentationLayer] frame]; 
[color.layer removeAllAnimations]; 
+0

它說:實例方法'-removeAllAnimations'找不到(返回類型默認爲'id') – user2245512 2013-04-04 16:04:14

+0

您是否已經導入/鏈接QuartzCore框架? – lukaswelte 2013-04-05 07:13:02