swift – 使用NSAnimationContext淡出NSButton
发布时间:2020-12-14 02:24:20 所属栏目:百科 来源:网络整理
导读:我有一个简单的 Swift macOS应用程序(使用Xcode 8.2.1),它包含一个NSButton.当我点击按钮时,我希望它在指定的时间段内淡出.我以为我可以使用NSAnimationContext,但无论我设置上下文持续时间的值,按钮几乎立即淡出.这不是正确的方法吗? class ViewController
我有一个简单的
Swift macOS应用程序(使用Xcode 8.2.1),它包含一个NSButton.当我点击按钮时,我希望它在指定的时间段内淡出.我以为我可以使用NSAnimationContext,但无论我设置上下文持续时间的值,按钮几乎立即淡出.这不是正确的方法吗?
class ViewController: NSViewController { @IBOutlet weak var basicButton: NSButton! override func viewDidLoad() { super.viewDidLoad() } @IBAction func basicButtonClicked(_ sender: NSButton) { NSAnimationContext.runAnimationGroup({ (context) in context.duration = 10.0 self.basicButton.animator().alphaValue = 1 }) { self.basicButton.animator().alphaValue = 0 } } }
我误解了动画师在动画期间的价值观.设置它的正确方法是:
@IBAction func basicButtonClicked(_ sender: NSButton) { NSAnimationContext.runAnimationGroup({ (context) in context.duration = 10.0 // Use the value you want to animate to (NOT the starting value) self.basicButton.animator().alphaValue = 0 }) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |