IPHONE - fade in et fade out d'un UIImageView avec des temps
-
21-09-2019 - |
Question
Je voudrais faire un fondu et d'un UIImageView en utilisant différents moments, disons, en utilisant les paramètres suivants:
- t = 0 ... UIImageView de alpha = 0
- t = 0.5s ... de UIImageView alpha = 0,7
- t = 0.7s ... alpha = 0 de UIImageView
Est-ce possible de faire avec CAAnimation ou une autre méthode? Comment cela peut-il être fait?
Merci pour toute aide!
La solution
Vous devriez probablement dans CAKeyframeAnimation. Il vous laisse définir des valeurs pour les points de temps multiples.
Autres conseils
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];
}
elle pourra être utile
UIView a une setAnimationDidStopSelector: méthode que vous pouvez utiliser. Il suffit de configurer votre fondu en animation à l'aide d'un bloc beginAnimations et réglez le sélecteur didStop à une autre méthode qui ne contient que le fondu bloc d'animation. Chacun de ces blocs d'animation peuvent avoir des durées d'animation.
Quelque chose comme ceci:
[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];
}