I am using UIViewPropertyAnimator
to animate interaction with my view (swiping between cards). Everything was working fine, until recently I got following crash in production:
Fatal Exception: NSInternalInconsistencyException
It is an error to release a paused or stopped property animator. Property animators must either finish animating or be explicitly stopped and finished before they can be released.
Since the Crashlytics didn't really provide more context, or I can do is to make sure that all my animators get always finished before the viewController
is released.
In one of my attempts I tried to make sure that when I create a new animator, the old one is stopped and finished:
fileprivate var runningAnimator: UIViewPropertyAnimator? {
didSet {
if let oldValue = oldValue {
print(">> before stopping: \(oldValue.isRunning)")
oldValue.stopAnimation(false)
print(">> after stopping: \(oldValue.isRunning)")
oldValue.finishAnimation(at: .end)
print(">> after finishing: \(oldValue.isRunning)")
}
}
}
However, now my app started to crash with this error:
'NSInternalInconsistencyException', reason: 'finishAnimationAtPosition: should only be called on a stopped animator!'
while printing on the output this:
>> before stopping: true
>> after stopping: true
So obviously the oldValue
animator is still running even after calling oldValue.stopAnimation(false)
.
How is this possible?