I would like to use a property animator, as it gives me control over stopping the animation and its progress. I'm trying to achieve a cross-dissolve effect when setting the image of an image view. I can do this easily with a view animation like so:
UIView.transition(
with: imageView,
duration: 2,
options: .transitionCrossDissolve,
animations: { [weak self] in
self?.imageView.image = anImage
},
completion: {
// do something
}
)
I tried something along the lines of:
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()
Any help would be greatly appreciated.
I think you'll have much better luck using two image views -- one on top of the other.
Then use
UIViewPropertyAnimatorto animate the.alphaproperty of the "on top" image view.Quick example:
Looks like this... as you drag the slider back and forth, it animates the "swift" logo image view's alpha: