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

查看:108
本文介绍了如何在使用“自动布局"时使用动画折叠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天全站免登陆