Autostart view controller in container

I have an NSWindow in which there are 2 types of container, all in one xib, for example:

Screen shot 1

In another xib, I have a sidebar view controlled by another view controller, for example:

Screenshothot 2

When I add a subview to the container view, I do it like this:

self.sidebarViewController.view.frame = self.sidebarContainer.bounds; [self.sidebarContainer addSubview:self.sidebarViewController.view]; 

When I create and start and resize this window, this happens:

Screen shot 3

The container correctly tracks the height of the add-in, but the sidebar view itself does not track the height of the container.

How can I adjust things so that the viewing height of sidebarVCs tracks the height of the container when the window is resized?


I think I solved it like this:

 [self.sidebarViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO]; NSLayoutConstraint *w = [NSLayoutConstraint constraintWithItem:self.sidebarViewController.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:150.0]; NSArray *c1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:@{ @"view":self.sidebarViewController.view }]; [self.sidebarContainer addConstraints:c1]; [self.sidebarContainer addConstraint:w]; 

I still don't understand why the autoresizemask layout constraint doesn't do this automatically, but I think I'm closer to understanding the relationship between the views here.

+4
source share
1 answer

Use NSBoxes as containers. In the sidebar, add an NSBox inside an NSView and limit all sides of the view. Then, when you want to swap in the sidebar, you can call the container (NSBox object) setContentView :.

0
source

Source: https://habr.com/ru/post/1491989/


All Articles