animación alpha change


Siempre he trabajado con Flash, y es bastante fácil cambiar los valores alfa entre un fotograma y otro. ¿Hay alguna manera de hacer esto en xcode 4? Estoy animando un logotipo y necesito que el primer png desaparezca mientras el segundo comienza a aparecer. tnx!

Author: Phlibbo, 2011-05-19

3 answers

Alternativamente al método de esqew (que está disponible antes de iOS 4, por lo que probablemente debería usarlo en su lugar si no planea limitar su trabajo a solo iOS 4), también existe [UIView animateWithDuration:animations:], que le permite hacer la animación en un bloque. Por ejemplo:

[UIView animateWithDuration:3.0 animations:^(void) {
    image1.alpha = 0;
    image2.alpha = 1;
}];

Bastante simple, pero de nuevo, esto está disponible solo en iOS 4, así que tenlo en cuenta.

 47
Author: nil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-19 23:20:45

Otra solución, fade in y fade out:

//Disappear
[UIView animateWithDuration:1.0 animations:^(void) {
       SplashImage.alpha = 1;
       SplashImage.alpha = 0;
}
completion:^(BOOL finished){
//Appear
   [UIView animateWithDuration:1.0 animations:^(void) {
      [SplashImage setImage:[UIImage imageNamed:sImageName]];
      SplashImage.alpha = 0;
      SplashImage.alpha = 1;
 }];
}];
 11
Author: ChavirA,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-03 20:29:47

Esto es bastante simple en realidad. Coloque el siguiente código donde desea que ocurra la animación:

[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[image1 setAlpha:0];
[image2 setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above

Puede leer más sobre estos métodos en este documento.

Si quieres trabajar con una estructura a la que te referiste en tu comentario sobre esta pregunta:

[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[[introAnimation objectAtIndex:0] setAlpha:0];
[[introAnimation objectAtIndex:1] setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above

... debería funcionar.

 6
Author: esqew,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-20 20:09:52