3 回答
TA贡献1802条经验 获得超5个赞
使用新的基于块的UIKit动画方法可以更加简单。
假设以下代码位于视图控制器中,并且您要交叉溶解的UIImageView是可通过属性self.imageView寻址的self.view的子视图。然后,您需要做的就是:
UIImage * toImage = [UIImage imageNamed:@"myname.png"];
[UIView transitionWithView:self.imageView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = toImage;
} completion:nil];
做完了
并在Swift中进行操作,就像这样:
let toImage = UIImage(named:"myname.png")
UIView.transitionWithView(self.imageView,
duration:5,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { self.imageView.image = toImage },
completion: nil)
斯威夫特3.0
let toImage = UIImage(named:"myname.png")
UIView.transition(with: self.imageView,
duration: 0.3,
options: .transitionCrossDissolve,
animations: {
self.imageView.image = toImage
},
completion: nil)
TA贡献1789条经验 获得超10个赞
是的,您说的是绝对正确的,那就是做到这一点的方法。我编写了此方法,并始终使用它来淡化我的图像。我CALayer为此处理。您需要为此导入Core Animation。
+ (void)fadeInLayer:(CALayer *)l
{
CABasicAnimation *fadeInAnimate = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimate.duration = 0.5;
fadeInAnimate.repeatCount = 1;
fadeInAnimate.autoreverses = NO;
fadeInAnimate.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimate.toValue = [NSNumber numberWithFloat:1.0];
fadeInAnimate.removedOnCompletion = YES;
[l addAnimation:fadeInAnimate forKey:@"animateOpacity"];
return;
}
您可以执行相反操作以淡出图像。之后淡出。您只需将其从Superview中删除(即UIImageView)。[imageView removeFromSuperview]。
- 3 回答
- 0 关注
- 736 浏览
添加回答
举报