I'm using UIViewPropertyAnimator
to control the progress of multiple animations. I have a 2d array of UIView subclasses. I want to display all elements at each index at once. For some reason the compiler won't let me add new animations with a delay by using addAnimations(_:delayFactor:)
method. Can someone tell me what am I doing wrong here?
// I'm creating a new viewAnimator without any animations. No problems here
self.viewAnimator = UIViewPropertyAnimator(duration: self.frameDelay * Double(self.spillBubbles.count),
curve: .easeIn,
animations: {})
for (index, views) in self.spillBubbles.enumerated() {
views.forEach({ self.simulationView.addSubview($0) })
// That's where the compiler error occurs
self.viewAnimator!.addAnimations({
views.forEach({ self.simulationView.addSubview($0) })
}, delayFactor: Double(index) / Double(self.spillBubbles.count))
}
When I try to call .addAnimations I get the following message:
Cannot invoke 'addAnimations' with an argument list of type '(() -> (), delayFactor: Double)'
What am I doing wrong here? The same closure called in the UIViewPropertyAnimator
initializers works without any issues.
The error message is pretty clear. Just look at the docs if it isn't clear enough:
https://developer.apple.com/documentation/uikit/uiviewpropertyanimator/1648370-addanimations
The delayFactor
needs to be a CGFloat, not a Double.