2010-09-08 12 views

Odpowiedz

12

Poszukujesz metod -beginAnimations:context: i na UIView.

W skrócie, można zrobić coś takiego:

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

Idealnie! Dziękuję Ci bardzo :) – Nippysaurus

13

Dla iOS4 i później nie powinno się używać beginAnimations:context i commitAnimations, gdyż zniechęca w documentation.

Zamiast tego należy użyć jednej z metod opartych na blokach.

Powyższy przykład będzie wyglądać następująco:

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

Oto przykład z UILabel - animacja przesuwa się etykietę z lewej w 0,3 sekundy.

// 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; 
}];