Comment puis-je animer le mouvement d'une label ou d'une image? Je voudrais juste faire une transition lente d'un endroit sur l'écran à l'autre (rien d'extraordinaire).
Vous searchz les -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];
Pour ios4 et plus tard, vous ne devriez pas utiliser beginAnimations:context
et commitAnimations
, car ils sont déconseillés dans la documentation .
Au lieu de cela, vous devez utiliser l'une des methods basées sur les blocs.
L'exemple ci-dessus ressemblerait à ceci:
[UIView animateWithDuration:0.3 animations:^{ // animate the following: myLabel.frame = newRect; // move to new location }];
Voici un exemple avec un UILabel
– l'animation fait glisser l'label 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; }];