0

I the issue I'm having has to do with the coordinate system in Cocoa but I really don't know. This is all happening in the top pane of a horizontal NSSplitView.

Very simply, I'm trying to position one NSBox right below a second one (I load custom views into the boxes - that all works fine). The top box's top-left corner is at the top-left corner of the pane and never changes. If the height of the top NSBox shrinks I want the top of the second NSBox to slide right up below it. Conversely, if the top NSBox's height increases I want the bottom NSBox to slide down.

This code gets called twice. Box is correct (first time top box, second time bottom box) and v is correct (this is the view I'm loading into the box - this works fine and it is what is causing the height to change in the top box).

 NSSize destBoxSize = [[box contentView] frame].size;  //the size of the box in the view to load the view into
 NSSize newViewSize = [v frame].size;  // the size of the view to be loaded 

 float deltaWidth = [horizSplitView frame].size.width - destBoxSize.width;
 float deltaHeight = newViewSize.height - destBoxSize.height;
 NSRect boxFrame = [box frame];
 boxFrame.size.height += deltaHeight;
 boxFrame.size.width += deltaWidth; 
 boxFrame.origin.y -= deltaHeight;

 NSLog(@"vc=%@ boxFrame x%f y%f h%f w%f", nibName, boxFrame.origin.x, boxFrame.origin.y, boxFrame.size.height, boxFrame.size.width);

 // Clear the box for resizing
 [box setContentView:nil]; 
 [box setContentView:v];
 [box setFrame:boxFrame];
tshepang
  • 12,111
  • 21
  • 91
  • 136
Mark
  • 11
  • 1
  • 3
  • If you add four spaces to each line of the code, it will be highlighted; in that way, it easier to read it, and see it between the other words. – apaderno Dec 22 '09 at 04:56
  • “I'm trying to position one NSBox right below a second one (I load custom views into the boxes - that all works fine). … If the height of the top NSBox shrinks I want the top of the second NSBox to slide right up below it. Conversely, if the top NSBox's height increases I want the bottom NSBox to slide down.” You mean with the lower box's height never changing? What fills the space, then? – Peter Hosey Dec 22 '09 at 05:32
  • Please format your code with the code button (101 010). Just select the code (with the comments), cut it, click the editor's code button and paste your code again where it says "enter code here". – Elise van Looij Dec 22 '09 at 11:44
  • Sorry about formatting the code. The top box height changes. The lower box height never does. It should extend from the bottom of the top box to the horizontal divider of a split view. Thanks for all your comments so far. – Mark Dec 22 '09 at 21:16

1 Answers1

0

What you want to do is not so hard, but it will need some subclassing. First of all, you need to subclass NSSplitView and either and override either -(void)init or -(void)awakeFromNib to add this line:

[self setAutoresizesSubviews:YES];  //

Then you need to subclass the two boxes and set their auto resizing masks, either in -(void)init or in - (void)viewWillMoveToSuperview:(NSView *)newSuperView. For the first box you'll probably want:

[newInstance setAutoresizingMask:NSViewNotSizable];

For the second bbox you'll probably want:

[newInstance setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];

See also NSView. It takes a bit of experimenting to get the right combination, but then it works quite nicely.

Elise van Looij
  • 4,162
  • 3
  • 29
  • 52