13
votes

Is there a way to prevent a view from being resized if the view controller is presented as a sheet using the method presentViewControllerAsSheet or using a segue of style "sheet"?

Note that modal/show segues can be implanted to a window controller which can be set as non resizable from the storyboard itself. Segues of type popover are non-resizable by default.

resizable sheet

4

4 Answers

11
votes

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?

2
votes

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

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

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

0
votes

the above methods did not work for me . self.view.autoresizesSubviews = NO; this line in viewcontroller should do the trick if the above methods didnt work