gpt4 book ai didi

cocoa - 如何在使用自动布局时用动画折叠 NSSplitView Pane ?

转载 作者:行者123 更新时间:2023-12-03 16:06:53 29 4
gpt4 key购买 nike

我已经尝试了我能想到的一切,包括我在 SO 和其他邮件列表上找到的所有建议,但我无法弄清楚如何以编程方式折叠 NSSplitView Pane 自动布局打开时的动画。

这是我现在所拥有的(为了好玩而用 Swift 编写的),但它在很多方面都失败了:

@IBAction func toggleSourceList(sender: AnyObject?) {
let isOpen = !splitView.isSubviewCollapsed(sourceList.view.superview!)
let position = (isOpen ? 0 : self.lastWidth)

if isOpen {
self.lastWidth = sourceList.view.frame.size.width
}

NSAnimationContext.runAnimationGroup({ context in
context.allowsImplicitAnimation = true
context.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
context.duration = self.duration

self.splitView.setPosition(position, ofDividerAtIndex: 0)
}, completionHandler: { () -> Void in
})
}

所需的行为和外观是 Mail.app 的行为和外观,它的动画效果非常好。

我有一个完整的示例应用程序,位于 https://github.com/mdiep/NSSplitViewTest .

最佳答案

Objective-C:

[[splitViewItem animator] setCollapse:YES]

swift :

splitViewItem.animator().collapsed = true

来自 Apple 的帮助:

Whether or not the child ViewController corresponding to the SplitViewItem is collapsed in the SplitViewController. The default is NO. This can be set with the animator proxy to animate the collapse or uncollapse. The exact animation used can be customized by setting it in the -animations dictionary with a key of "collapsed". If this is set to YES before it is added to the SplitViewController, it will be initially collapsed and the SplitViewController will not cause the view to be loaded until it is uncollapsed. This is KVC/KVO compliant and will be updated if the value changes from user interaction.

关于cocoa - 如何在使用自动布局时用动画折叠 NSSplitView Pane ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26664759/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com