2010-09-08 75 views

回答

12

您正在通過UIView尋找-beginAnimations:context:-commitAnimations方法。

概括地說,你這樣做:

[UIView beginAnimations:nil context:NULL]; // animate the following: 
myLabel.frame = newRect; // move to new location 
[UIView setAnimationDuration:0.3]; 
[UIView commitAnimations]; 
+0

完美!非常感謝你 :) – Nippysaurus 2010-09-19 09:03:52

13

對於iOS4的,以後你不應該使用beginAnimations:contextcommitAnimations,因爲這些都是在documentation氣餒。

相反,您應該使用基於塊的方法之一。然後

上面的例子應該是這樣的:

[UIView animateWithDuration:0.3 animations:^{ // animate the following: 
    myLabel.frame = newRect; // move to new location 
}]; 
3

這是一個帶UILabel一個例子 - 動畫滑動從在0.3秒左標籤。

// Save the original configuration. 
CGRect initialFrame = label.frame; 

// Displace the label so it's hidden outside of the screen before animation starts. 
CGRect displacedFrame = initialFrame; 
displacedFrame.origin.x = -100; 
label.frame = displacedFrame; 

// Restore label's initial position during animation. 
[UIView animateWithDuration:0.3 animations:^{ 
    label.frame = initialFrame; 
}];