简体   繁体   中英

Window animates width but not height

I have a preferences window with a NSTabViewController hooked up to the toolbar for selecting tabs. 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:

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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