Re: Subview and window size
Re: Subview and window size
- Subject: Re: Subview and window size
- From: Quincey Morris <email@hidden>
- Date: Sat, 19 Dec 2009 11:11:19 -0800
On Dec 19, 2009, at 09:56, Kevin Walzer wrote:
> Let me clarify what I'm trying to do: I want the subview to be the same dimensions as the entire window. That would mean, basically, that I want it its frame to be the same as the frame for the window's contentView.
>
> Right now it's not the same size. Right now it takes up 1/4 of the window.
>
> How do I set the bounds/geometry to be the same as the toplevel frame in the window?
The trouble is, your question is actually more nebulous than you think it is. There are (at least) 3 issues that may or may not have their own subtleties:
1. Geometry.
2. View hierarchy.
3. Initialization timing.
The short answer is that you need to set your view's *frame* rect to the *bounds* rect of the ancestor view you want to match. The ancestor view in this case is the window's content view (which is the root of the window's entire view hierarchy).
This is easy if your view is a subview of the window content view. If it's merely a descendant view (subview of a subview, etc), then you need to do a coordinate transformation from the bounds coordinate system of the ancestor to the bounds coordinate system of the immediate superview.
Of course, this needs to be done at a time when the window already exists, otherwise the requisite geometry may not be available. And you should follow the rules/conventions/patterns for initialization that view subclasses generally follow.
All of this is clearly documented:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaViewsGuide/Introduction/Introduction.html
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW18
and those documents should be amongst your essential reading.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden