2012-03-30 17 views
31

Me gustaría tener una imagen en mi aplicación de iPhone "emergente" en la pantalla en lugar de simplemente aparecer. Con "pop-in" quiero decir que crecerá desde un pequeño punto hasta su tamaño real. Como referencia, esto es exactamente lo mismo que el efecto de animación "pop" en Keynote. Soy completamente nuevo en las animaciones de iOS, así que si alguien pudiera indicarme los efectos de animación que tendría que usar, sería muy apreciado.iOS - Efectos de animación - Imagen emergente

Gracias

Brian

ACTUALIZACIÓN He añadido el código de las siguientes sugerencias. Esto funciona pero escala mi imagen hacia abajo, en lugar de hacia arriba. Sé que es porque tengo 0.01 como el tamaño de la escala de transformación, pero me gustaría saber cómo puedo comenzar con una imagen de tamaño 0.0 y escalar hasta 1. ¿Es solo cuestión de establecer el tamaño de la imagen en 0? Gracias

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration: 0.2]; 
image.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

Respuesta

78

El efecto que buscas es algo como esto:

// instantaneously make the image view small (scaled to 1% of its actual size) 
view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    // animate it to the identity transform (100% scale) 
    view.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
    // if you want to do something once the animation finishes, put it here 
}]; 
+1

¿Hay alguna manera de escalar la imagen desde un punto diferente al centro? – tiguero

+5

Sí, cambie el [punto de anclaje] de su capa (http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/c_ref/CALayer) . 'theView.layer.anchorPoint = CGPointMake (0, 0) 'hará que la escala de la vista se encuentre en la parte superior izquierda; '(1, 1)' es su parte inferior derecha. –

+0

¿Qué tipo de objeto es la imagen variable? –

0

tienes que animar el marco de la vista, para que se contraiga desde cero hasta el estado final. Esto se puede hacer, por ejemplo, con la animación de bloques UIView.

Así que, por ejemplo, comience con su vista como una propiedad de IBOutlet self.myView con el tamaño y la posición final, pero establezca la bandera oculta. Luego, cuando se desea que aparezca el siguiente uso:

// Save old frame as final stater and set it to zero size for the start of the animation 
// But keep the same center position, so it just grows and don't move around 
CGRect oldFrame = self.myView.frame; 
CGRect oldCenter = self.myView.center; 

self.myView.frame = CGRectZero; 
self.myView.center = oldCenter; 

self.myView.hidden = NO; 

NSTimeInterval duration = 0.3; 

[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
       // New position and size after the animation should be the same as in Interface Builder 
       self.myView.frame = oldFrame 
    } 
        completion:^(BOOL finished){ 
               // You can do some stuff here after the animation finished 
        }]; 
+0

Eso ... probablemente no funcione bien. Animar el marco de una vista de imagen lo obliga a volver a dibujarse en cada fotograma de la animación. –

+1

@NoahWitherspoon sería una transformación una mejor manera? – Thyraz

+0

Sí. Animar desde CGAffineTransformMakeScale (0.01,0.01) a CGAffineTransformIdentity haría el truco. –

0

Swift 2.0 versión

view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in 
     // animate it to the identity transform (100% scale) 
     self.view.transform = CGAffineTransformIdentity; 

     }) { (finished) -> Void in 
     // if you want to do something once the animation finishes, put it here 
    } 
4

si quiere algo así como Facebook hace que le guste cualquier publicación y luego use esto

-(void)animateButton:(UIButton *)sender{ 
UIButton * btn = (UIButton *)sender; 
[UIView animateWithDuration:0.3/1.5 animations:^{ 
    btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3/2 animations:^{ 
     btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button 
     }]; 
    }]; 
}];} 

a llamar a este método cuando desea animar la vista

si tiene texto e imagen en el botón y lo que desea es animar la imagen del botón a continuación, basta con sustituir "btn" con "BTN. imageView ", esto solo producirá animación en la propiedad de vista de imagen del botón. Espero que ayude Todo lo mejor.

0

Para que usted tendrá que utilizar un simple UIView

Añadir la UIView a la vista actual.

- (void) initPopUpView 
{ 
    popup.alpha = 0; 
    popup.frame = CGRectMake (160, 240, 0, 0); 
    [self.view addSubview:popup]; 
} 

- (void) animatePopUpShow 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationWillStartSelector:@selector(initPopUpView)]; 

    popup.alpha = 1; 
    popup.frame = CGRectMake (20, 40, 300, 400); 

    [UIView commitAnimations]; 
} 
Cuestiones relacionadas