UIViewPropetyAnimator crossfade

问题描述 投票:0回答:0

我想使用属性动画器,因为它可以让我控制停止动画及其进度。我试图在设置图像视图的图像时实现交叉溶解效果。我可以使用像这样的视图动画轻松地做到这一点:

UIView.transition(
    with: imageView,
    duration: 2,
    options: .transitionCrossDissolve,
    animations: { [weak self] in
        self?.imageView.image = anImage
    },
    completion: {
        // do something
    }
) 

我尝试了以下方法:

let animator = UIViewPropertyAnimator(duration: 2, curve: .linear)
animator.addAnimations {
    self.imageView.alpha = 0
}
animator.addAnimations {
    self.imageView.image = image
}
animator.addAnimations {
    self.imageView.alpha = 1
}
animator.startAnimation()

任何帮助将不胜感激。

ios swift uiview uiviewanimation
© www.soinside.com 2019 - 2024. All rights reserved.