IPHONE - intensificar y atenuar cabo de un UIImageView con diferentes tiempos
-
21-09-2019 - |
Pregunta
Me gustaría hacer un fundido de entrada y salida de un UIImageView utilizando diferentes momentos, digamos, utilizando los siguientes parámetros:
- t = 0 ... UIImageView de alfa = 0
- t = 0,5 s ... alfa de UIImageView = 0,7
- t = 0,7 s ... alfa de UIImageView = 0
Es posible esto que ver con CAAnimation u otro método? ¿Cómo se puede hacer esto?
Gracias por cualquier ayuda!
Solución
Probablemente debería mirar en CAKeyframeAnimation. Va permiten establecer valores para múltiples puntos de tiempo.
Otros consejos
if (imgDefault.alpha == 0.0) {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationDelegate: self];
imgDefault.alpha = 1.0;
[UIView commitAnimations];
}
else {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationDelegate: self];
imgDefault.alpha = 0.0;
[UIView commitAnimations];
}
creo que sirve
UIView tiene una setAnimationDidStopSelector: método que se puede utilizar. Simplemente configurar su aparición gradual de la animación usando un bloque beginAnimations y ajuste el selector didStop a otro método que contiene sólo el fundido de salida bloque de animación. Cada uno de estos bloques de animación puede tener diferentes duraciones de animación.
Algo como esto:
[UIView beginAnimations:next context:context];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:)];
myView.alpha = 0.7;
[UIView commitAnimations];
-(void)fadeOut:(NSString*)animationID finished:(BOOL)finished context:(void*)context {
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.2];
myView.alpha = 0.0;
[UIView commitAnimations];
}