views:

1541

answers:

3
A: 

Try resizeSubviewsWithOldSize: or setAutoresizesSubviews:.

Peter Hosey
I'm not sure what you mean here. Parent's resizeSubviewsWithOldSize gets called, setAutoresizesSubviews is set to yes. Can you provide some more guidance please?
EightyEight
The former is because of the latter—if autoresizesSubviews is set to YES, then resizeSubviewsWithOldSize: should get called automatically. Since you have it so set and that is happening, I'm stumped, too. Sorry.
Peter Hosey
+2  A: 

This code

NSView* superView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
NSView* subView   = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
[superView addSubview:subView];

[superView setAutoresizesSubviews:YES];
[subView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

NSLog(@"subview's frame before resizing: %@", NSStringFromRect([subView frame]));
[superView setFrame:NSMakeRect(0, 0, 200, 100)];
NSLog(@"subview's frame after  resizing: %@", NSStringFromRect([subView frame]));

does give the expected result:

[...] subview's frame before resizing: {{0, 0}, {100, 100}}
[...] subview's frame after  resizing: {{0, 0}, {200, 100}}

Your problem is elsewhere. I expect that one of your container views is not a part of the view hierarchy of the window at the time when the resize occurs.

A good solution for your problem might be the use an NSTabView without tabs, because then all your views are at all times in the window (possibly hidden) and the tabview takes care of the resizing.

Another solution is to put several views on top of each other and use setHidden: to show only one.

Nikolai Ruhe
That's an interesting idea, about rendering all the views. Unfortunately some of the views require quite a bit of processing, enough to be expensive. Great idea thought!
EightyEight
A: 

Turns out my approach is correct. I was setting the frame size to an incorrect value, thus I wasn't getting the expected behavior. Doh.

EightyEight