我想使用以下参数,使用不同的时间淡入和淡出UIImageView:
这可能与CAAnimation或其他方法有关吗? 怎么办?
感谢您的帮助!
答案 0 :(得分:6)
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];
}
希望有所帮助
答案 1 :(得分:3)
您应该查看CAKeyframeAnimation。它可以让你设置多个时间点的值。
答案 2 :(得分:2)
UIView有一个setAnimationDidStopSelector:方法,您可以使用它。只需使用beginAnimations块设置淡入淡出动画,并将didStop选择器设置为另一个仅包含淡出动画块的方法。每个动画块都可以有不同的动画持续时间。
这样的事情:
[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];
}