简体   繁体   中英

Why aren't my NSViews in my NSWindow resizing when the window is resized?

I'm pulling my hair out trying to figure why my views aren't resizing with my NSWindow on drag.

Okay, here's my structure:

  • Subclassed NSWindowController's View (Use Auto Layout Checked for window. Auto Resize checked for view. Window's View not hooked up to anything in IB, should it be?)
    • Various Buttons
    • Custom View (Auto Resizes Subviews checked)
      • Subclassed NSViewController's View (Auto Resizes Subviews & Translates Mask checked)
        • Various Subviews (Auto Resizes Subviews checked)
      • Subclassed NSViewController's View (Auto Resizes Subviews & Translates Mask checked)
        • Various Subviews (Auto Resizes Subviews checked)

I'm adding each of these views to my NSWindowController's Custom View. This is the only relevant method in my file:

-(void)setActiveView:(NSString*) viewString{
    if ([currentViewController view] != nil)
        [[currentViewController view] removeFromSuperview];    

    if ([viewString isEqualToString:kFirstView]){
        FirstViewController *viewController = [[FirstViewController alloc]initWithNibName:kFirstView bundle:nil];
        if (viewController != nil){
            currentViewController = viewController;
        }

    }

    else if ([viewString isEqualToString:kSecondView]){
        SecondViewController *viewController = [[SecondViewController alloc]initWithNibName:kSecondView bundle:nil];
        if (viewController != nil){
            currentViewController = viewController;
        }
    }

    //Resize Controller to Window's size.
    [[currentViewController view] setFrame:[myWindowView bounds]];

    //Embed current view into Custom View in host view.
    [myWindowView addSubview:[currentViewController view]];


}

The setFrame to resize does work when I change views, but not when I drag to resize my window. As far as I can tell, because setFrame works when I change views, the only one that really matters (but isn't working) is the Custom View inside my NSWindowController.

Also, this is how I bring this window forward:

    myController = [[MyWindowController alloc]initWithWindowNibName:@"MyWindow"];
    [myController showWindow:nil];

Yes I've already tried in my initwithframe:

[myWindowView setAutoresizesSubviews:YES];
[myWindowView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

What am I missing?

Try to do this without Auto Layout .

Try this:

  • Uncheck Use Auto Layout for window.

  • Go to Size inspector and make autosizing to Your Views like this:

    自动调整大小

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM