Is there any possibility to interrupt a UIView.transition
at its current state on iOS?
To give you a bit of context: I have a UIButton
where I need to animate the title color - the animation can have different delays attached to it, though. Since UIView.transition
does not support delays, I simply delayed execution of the entire block:
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
UIView.transition(with: button, duration: 0.4, options: [.beginFromCurrentState, .allowUserInteraction, .transitionCrossDissolve], animations: {
button.setTitleColor(selected ? .red : .black, for: .normal)
}, completion: nil)
}
The issue here is that, if this code is executed in quick succession with different delays, the outcome can be unexpected. So for example this could be called with selected=true, delay=0.5
and immediately after that with selected=false, delay=0.0
. In this scenario, the button would end up red even though it should be black.
Therefore, I am looking for a method to either have UIView.transform
with a delay, interrupt a UIView.transform
or make setTitleColor()
animatable through UIView.animate
.