Reputation: 961
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.
Upvotes: 15
Views: 4082
Reputation: 35032
This worked for me. The sheet is no longer resizable:
override func viewWillLayout() {
preferredContentSize = view.frame.size
}
Upvotes: 3
Reputation: 6606
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:
That's it, super easy! (Don't forget to set the window controller, as the initial controller).
Upvotes: 1
Reputation: 775
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
Upvotes: 0
Reputation: 61228
Have you tried setting your sheet view controller's -preferredContentSize
? Failing that, what about adding width and height NSLayoutConstraint
s to the view controller's view on -viewDidLoad
?
Upvotes: 12