swift – 使用NSAnimationContext淡出NSButton

swift – 使用NSAnimationContext淡出NSButton,第1张

概述我有一个简单的 Swift macOS应用程序(使用Xcode 8.2.1),它包含一个NSButton.当我点击按钮时,我希望它在指定的时间段内淡出.我以为我可以使用NSAnimationContext,但无论我设置上下文持续时间的值,按钮几乎立即淡出.这不是正确的方法吗? class ViewController: NSViewController { @IBOutlet weak va 我有一个简单的 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  })}
总结

以上是内存溢出为你收集整理的swift – 使用NSAnimationContext淡出NSButton全部内容,希望文章能够帮你解决swift – 使用NSAnimationContext淡出NSButton所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1089439.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存