2011-04-17 34 views
0

我用在IBAction爲(按下按鈕)方法的代碼:只有在UIButton動畫完成後才更新標籤?

CABasicAnimation *rotateButton; //don't forget to release 
rotateButton = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
rotateButton.fromValue = [NSNumber numberWithFloat:0]; 
rotateButton.toValue = [NSNumber numberWithFloat:((720*M_PI)/180)]; 
rotateButton.duration = 0.75; 
rotateButton.repeatCount = 1; 
[sender addAnimation:rotateButton forKey:@"720"]; 

,並有我想只更新後,這是完整的一個標籤。我想知道是否有一個簡單的例子,任何人都可以提供給我,讓標籤只在完成時更新,而不是在方法完成時更新。我知道你不能使用「@selector(animationDidStop:finished:context :)」,因爲蘋果不喜歡它。任何人的幫助?謝謝,麻煩您了!

回答

1

爲什麼不直接使用UIView動畫塊?

[UIView animateWithDuration:0.75 delay:0 options:0 animations:^{ 
    theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180); 
} completion:^{ 
    theLabel.text = @"Whatever"; 
}]; 

如果您需要4.x的預兼容性,使用舊的形式,UIView類方法+setAnimationDidStopSelector:,像這樣:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDidStopSelector:@selector(someMethodInWhichYouSetTheLabelText)]; 
    theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180); 
[UIView commitAnimations]; 
+0

我去了底部的代碼,因爲我希望它是4倍前。不幸的是,我對此感到陌生,並且在CGAffineTransformMakeRotation行中出現錯誤:「請求成員」轉換爲「不是結構或聯合的東西」....對於像我這樣的白癡有什麼想法? – BFBC 2011-04-17 00:30:23

+0

Scratch ....我拼寫錯誤... – BFBC 2011-04-17 03:33:17

+0

btw ..我唯一可以讓@selector工作在多個按鈕上並正確使用setAnimationDidStop @選擇器的方法是使用[UIView setAnimationDelegate:self]行[UIView commit動畫] – BFBC 2011-04-17 05:16:35

0

I know you cannot use "@selector(animationDidStop:finished:context:)"

其實你可以,只要給它另所以它不會與Apple內部方法衝突

關於你的問題:

CAAnimation Class Reference

delegate

Specifies the receiver’s delegate object.

animationDidStop:finished:

Called when the animation completes its active duration or is removed from the object it is attached to.

+0

另一個教訓。謝謝。 – BFBC 2011-04-17 00:31:58

相關問題