I want to animate (using any method) the change of the label's text in a macOS app.
With the code I provide, the change occurs when I click the button. I see no animation and no delay.
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var label1: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func button2(_ sender: NSButton) {
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 4.0
label1.stringValue = "long, long text"
label1.animator().sizeToFit()
})
}
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: