I have successfully loaded a view from an xib file on to a window(another xib) dynamically as a subview.
I understand that by default this subview is loaded in the first quadrant of the window i.e.,the subview is at the extreme left bottom of the window. It is the same case with my window as well.
Now the issue is that how do i place the subview elsewhere on the window. In other words, if i want to place the subview on the top of my window, how would i achieve it??
Also I would really appreciate if i can get an explanation for NSRect and frame for NSwindow objects..
If there are any methods in any of the APIs, please direct me to them.. Thanks in advance…
UPDATE:
@interface ViewAvailableItemsWindowController : NSObject {
IBOutlet NSWindow * viewAvailableItemsWindow; //Window in question
IBOutlet NSView * viewAvailableItemsView; //View in question
ItemSearchViewController * instanceItemSearchView; //ViewController object
}
@end
@implementation ViewAvailableItemsWindowController
-(void)awakeFromNib{
[viewAvailableItemsWindow makeKeyAndOrderFront:nil];
instanceItemSearchView = [[ItemSearchViewController alloc]initWithNibName:@"ItemSearchView" bundle:nil] ; //Initiating the viewController with the nib for the view.
[viewAvailableItemsView addSubview:[instanceItemSearchView view]]; //Adding the subview to the window..
}
-(void)dealloc{
[instanceItemSearchView release];
[super dealloc];
}
@end
This loads the view on the first quadrant of the window- i mean the bottom left corner of the window. I want the view to be placed on the top center of the window.
An NSRect is a rectangle. It’s composed of an origin and a size. An origin is a point, x and y. A size is width and height. From now on I’ll type rects as {{x, y}, {width, height}}
Each view has a frame. The frame of a view is the position of that view within its superview. Each view also has a bounds. The bounds of a view defines the internal coordinate system of the view. By default 0, 0 is in the lower left corner, and as X and Y increase you move to the right and up.
Example: If one view had a bounds of {{0, 0}, {100, 100}}, and you put another view inside of that view and set its frame to {{25, 50}, {10, 10}} then the subview would have the size 10×10, and be position 25 points to the right of the left edge, and 50 points up from the bottom.
The bounds size is almost always the same as the frame size. You typically do not set or adjust the bounds of a view unless you intend to scale or shift all of the subviews and custom drawing – this is an advanced thing to do.
So if you had something like this:
Where each box represents an NSView, and each view is a subview of the next. So A contains B, contains C. The bounds and frames of each of the views might be something like this: