2010-09-08 7 views

Répondre

12

Vous recherchez les méthodes -beginAnimations:context: et -commitAnimations sur UIView.

En un mot, vous faites quelque chose comme:

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

Parfait! Merci beaucoup :) – Nippysaurus

13

Pour iOS4 et plus tard vous ne devriez pas utiliser beginAnimations:context et commitAnimations, car ceux-ci sont découragés dans le documentation. À la place, vous devez utiliser l'une des méthodes basées sur les blocs.

L'exemple ci-dessus doit ressembler à ceci:

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

Voici un exemple avec un UILabel - l'animation glisse l'étiquette de la gauche en 0,3 secondes.

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