使用自动布局时如何折叠带有动画的 NSSplitView 窗格? [英] How to collapse an NSSplitView pane with animation while using Auto Layout?

查看:24
本文介绍了使用自动布局时如何折叠带有动画的 NSSplitView 窗格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've tried everything I can think of, including all the suggestions I've found here on SO and on other mailing lists, but I cannot figure out how to programmatically collapse an NSSplitView pane with an animation while Auto Layout is on.

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

Here's what I have right now (written in Swift for fun), but it falls down in multiple ways:

@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 的行为和外观,它的动画效果非常好.

The desired behavior and appearance is that of Mail.app, which animates really nicely.

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

I have a full example app available at https://github.com/mdiep/NSSplitViewTest.

推荐答案

Objective-C:

[[splitViewItem animator] setCollapse:YES]

斯威夫特:

splitViewItem.animator().collapsed = true

来自 Apple 的帮助:

From Apple’s help:

子ViewController是否对应SplitViewItem 折叠在 SplitViewController 中.默认是不.这可以用动画代理设置来动画折叠或展开.可以通过设置来自定义使用的确切动画在 -animations 字典中,键为collapsed".如果这是在将其添加到 SplitViewController 之前设置为 YES,它将是最初折叠并且 SplitViewController 不会导致视图将被加载,直到它展开.这是 KVC/KVO 兼容的并且会在值因用户交互而改变时更新.

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.

这篇关于使用自动布局时如何折叠带有动画的 NSSplitView 窗格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆