Animaciones simples [iPhone]
-
06-07-2019 - |
Pregunta
Tengo algunos botones UIB que me gustaría activar animaciones cortas de 5-10 cuadros cuando se presiona en el medio de la pantalla junto con otras cosas no relacionadas. ¿Puedo soltar un UIImageView en IB y actualizarlo, de alguna manera, mediante programación? No necesita ser demasiado complejo, ni siquiera me importa si está codificado, por ahora, ya que es un proyecto tan pequeño.
Gracias.
Solución
Aquí hay un ejemplo de la forma más fácil de hacer una animación con solo unos pocos cuadros:
Declare un IBOutlet UIImageView * timerAnimation
y vincúlelo a su UIIMageView en IB. Agregue una cierta cantidad de imágenes a sus recursos, como se ve a continuación. Luego cargue las imágenes en una matriz; vea el código:
timerAnimation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"timer00.png"],
[UIImage imageNamed:@"timer01.png"],
[UIImage imageNamed:@"timer02.png"],
[UIImage imageNamed:@"timer03.png"],
[UIImage imageNamed:@"timer04.png"],
[UIImage imageNamed:@"timer05.png"],
[UIImage imageNamed:@"timer06.png"],
[UIImage imageNamed:@"timer07.png"],
[UIImage imageNamed:@"timer08.png"],
[UIImage imageNamed:@"timer09.png"],
[UIImage imageNamed:@"timer10.png"],
[UIImage imageNamed:@"timer11.png"],
[UIImage imageNamed:@"timer12.png"],
[UIImage imageNamed:@"timer13.png"],
[UIImage imageNamed:@"timer14.png"],
[UIImage imageNamed:@"timer15.png"],
[UIImage imageNamed:@"timer16.png"],
[UIImage imageNamed:@"timer17.png"],
[UIImage imageNamed:@"timer18.png"],
[UIImage imageNamed:@"timer19.png"],
[UIImage imageNamed:@"timer20.png"],
[UIImage imageNamed:@"timer21.png"],
[UIImage imageNamed:@"timer22.png"],
[UIImage imageNamed:@"timer23.png"],
[UIImage imageNamed:@"timer24.png"],
[UIImage imageNamed:@"timer25.png"],
[UIImage imageNamed:@"timer26.png"],
[UIImage imageNamed:@"timer27.png"],
[UIImage imageNamed:@"timer28.png"],
[UIImage imageNamed:@"timer29.png"],
[UIImage imageNamed:@"timer30.png"],
[UIImage imageNamed:@"timer31.png"],
[UIImage imageNamed:@"timer32.png"],
[UIImage imageNamed:@"timer33.png"],
[UIImage imageNamed:@"timer34.png"],
[UIImage imageNamed:@"timer35.png"],
// [UIImage imageNamed:@"timer36.png"], save last picture for "times up"
nil];
timerAnimation.animationDuration = 5.0;
timerAnimation.animationRepeatCount = 1;
[timerAnimation startAnimating];
Esto ejecutará su animación hasta que llame a [timerAnimation stopAnimating];
Otros consejos
Sí Cree un IBOutlet en su UIImageView y puede actualizarlo desde el código. Por ejemplo, use su image para establecer el UIImage que se debe mostrar. O puede agregar la imagen a los recursos de su aplicación y asociarla con UIImageView en Interface Builder. Use archivos .png ya que el iPhone ha sido optimizado para ellos.
Dado que un UIImageView es un UIView, toda la animación principal habitual métodos se pueden utilizar.