NSViewController disable resize when presented as Sheet?

Swift 4:

override func viewDidAppear() {
   // any additional code
   view.window!.styleMask.remove(.resizable)
}

By the way you can do this without writing code, here is how:

  • Drag a Window Controller element to the Storyboard from the Object Library.
  • Connect the Window Controller to the specific View Controller which you want to disable resize.
  • On the Window Controller's Attributes uncheck Resize option.

disable resize window xcode


If you add these methods, the issue will be fixed.

- (void)updateViewConstraints NS_AVAILABLE_MAC(10_10) {

    [super updateViewConstraints];

}

- (void)viewWillLayout NS_AVAILABLE_MAC(10_10) {

    self.preferredContentSize = NSMakeSize(self.view.frame.size.width, self.view.frame.size.height);

}

After some more trying I found out this did the trick in viewDidLoad:

self.preferredContentSize = NSMakeSize(self.view.frame.size.width, self.view.frame.size.height);