Prevent resizing of a view controller presented as a sheet?

This worked for me. The sheet is no longer resizable:

override func viewWillLayout() {
    preferredContentSize = view.frame.size
}

None of the other solutions worked for me, so I ended up using an NSWindow as the sheet controller (rather than a NSViewController on its own).

Declare an NSWindowController object in your header file:

NSWindowController *detailWindow;

To open the window in the form of a sheet, use the following code:

NSStoryboard *storyFile = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
detailWindow = [storyFile instantiateInitialController];
[self.view.window beginSheet:detailWindow.window completionHandler:nil];

To close the window:

[self.view.window endSheet:detailWindow.window];

In order to stop the window sheet from being resized, simply set the NSWindow minimum/maximum size in interface builder:

enter image description here

That's it, super easy! (Don't forget to set the window controller, as the initial controller).


Have you tried setting your sheet view controller's -preferredContentSize? Failing that, what about adding width and height NSLayoutConstraints to the view controller's view on -viewDidLoad?