2010-09-08 9 views

Respuesta

12

Está buscando los métodos -beginAnimations:context: y -commitAnimations en UIView.

En pocas palabras, usted hacer algo como:

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

¡Perfecto! Muchas gracias :) – Nippysaurus

13

Para iOS4 y más tarde no debería utilizar beginAnimations:context y commitAnimations, ya que estos no se animan en el documentation.

En su lugar, debe utilizar uno de los métodos basados ​​en bloques.

El ejemplo anterior podría tener el siguiente aspecto:

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

Aquí se muestra un ejemplo con un UILabel - la animación se desliza la etiqueta de la izquierda en 0,3 segundos.

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