简体   繁体   English

窗口使宽度动画但不使高度动画

[英]Window animates width but not height

I have a preferences window with a NSTabViewController hooked up to the toolbar for selecting tabs. 我有一个带有NSTabViewController的首选项窗口,该窗口连接到用于选择选项卡的工具栏。 I want the window to be resizable, and to resize if necessary when switching tabs to fit the new tab's size. 我希望窗口可以调整大小,并在切换选项卡以适应新选项卡的大小时,如有必要,可以调整窗口的大小。

I'm subclassing NSTabViewController with the following overload: 我用以下重载将NSTabViewController子类NSTabViewController

override var selectedTabViewItemIndex: Int
{
  didSet
  {
    guard let view = tabViewItems[selectedTabViewItemIndex].view,
          let window = view.window
    else { return }

    let minSize = view.fittingSize
    let contentRect = NSWindow.contentRect(forFrameRect: window.frame,
                                           styleMask: window.styleMask)
    let minRect = NSRect(origin: contentRect.origin, size: minSize)
    let newRect = minRect.union(contentRect)
    let newFrame = NSWindow.frameRect(forContentRect: newRect,
                                      styleMask: window.styleMask)

    window.animator().setFrame(newFrame, display: true, animate: true)
  }
}

The result is that it animates resizing horizontally, and at the end it suddenly resizes vertically as well. 结果是它会在水平方向调整动画大小,最后突然在垂直方向调整大小。 How do I get it to just animate both directions at once? 如何获得同时对两个方向进行动画处理的效果?

Do you have height constraints on any of the tabs? 您是否在任何标签上都设置了高度限制? Those might prevent the window from getting larger (even while offscreen). 这些可能会阻止窗口变大(即使在屏幕外)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM