UIViewPropertyAnimator has an addCompletion
technique that permits you to present a block of code to be executed when the animation ends:
func addCompletion(_ completion: @escaping (UIViewAnimatingPosition) -> Void)
When I attempt to use an animator in a Job and I name that technique, I get a warning:
| Think about using asynchronous various perform
Certain sufficient, there is an asynchronous various perform:
func addCompletion() async -> UIViewAnimatingPosition
However I can not make any sense of this. The place’s the block that’s to be run when the animation completes? In truth, I discover that if I name this technique, any code that follows is not even run. Is that this just a few huge bug in Apple’s provision of async/await options?
This is a synthetic instance to be used in a view controller:
override func viewDidLoad() {
tremendous.viewDidLoad()
Job {
UIViewPropertyAnimator.runningPropertyAnimator(
withDuration: 2,
delay: 2,
choices: [],
animations: {
self.view.alpha = 0
}
).addCompletion { [weak self] _ in
self?.view.alpha = 1
}
}
}
You will note the warning on the .addCompletion
line. How would you rewrite the code in order that it nonetheless works (the view disappears after which reappears) however the warning goes away?