What I understand from what you show:
- the change of text should be done in the completion handler of the animation
- but it will not be possible to animate the sizeToFit
- stated otherwise, the change from "oldText" to "long, long text" cannot be animated the way you want ; the animation is an image "morphing" animation, not a text substitution.
In your case, as sizeToFit is not a property for animation, the delay is not applied !
Test the following and see difference: prints after 4 seconds now.
@IBAction func animate2LabelAction(_ sender: NSButton) {
self.labelForAnimation.stringValue = "short text"
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 4.0
// labelForAnimation.animator().sizeToFit()
labelForAnimation.animator().alphaValue = 0.5 // This is animatable
}, completionHandler: {
print("Completion") } )
}
Or add label change in completion:
@IBAction func animate2LabelAction(_ sender: NSButton) {
self.labelForAnimation.stringValue = "short text"
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 4.0
// labelForAnimation.animator().sizeToFit()
labelForAnimation.animator().alphaValue = 0.5
}, completionHandler: {
self.labelForAnimation.stringValue = "long, long text"
print("Completion") } )
}