Re: Views, frames, and bounds
Re: Views, frames, and bounds
- Subject: Re: Views, frames, and bounds
- From: Jamie Hardt <email@hidden>
- Date: Sat, 18 Oct 2008 22:06:13 -0700
On Oct 18, 2008, at 8:04 PM, DKJ wrote:
I am unable to understand the relation between the frame and the
bounds of an NSView. I've read the documentation in the View
Programming Guide, and also played around with them myself in a
practice project. In the latter, I tried drawing their rectangles in
different colours, but couldn't get both to display. So I'm still at
a loss. Can someone point me towards other documentation that might
get through the fog?
Do make sure you've read this: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/chapter_3_section_3.html#/
/apple_ref/doc/uid/TP40002978-CH10-SW9
The -frame and -bounds are two properties of an NSView, both
rectangles. The frame is the the position of the view within its
superview, thus, if you add a subview "B" to a view "A" and make it's
rect {0,0,100,100}, it'll be a 100x100 box in the lower-left corner of
"A". The bounds give the visible rectangle of the NSView in its own
coordinate system; by default it has an origin of (0,0) and the same
dimensions as the frame you gave when you initialized it, but it can
be modified later. Thus, the bounds of view "B" can be {0,0,200,100}
and this would cause the content of view "B" to be scrunched 2x from
left to right.
When you give drawing commands in drawRect, all coordinates you give
are with regard to the *bounds* of the view. SO, if you took the
hypothetical view "B" above and stroked from (0,0) to (100,0), the
line would only go halfway across the view (50 pixels), as its
bounds.size.width are 2x of its frame.size.width.
Hope this helps. Post your code, as you might have the rects all
right but may be doing something else incorrectly.
Jamie Hardt
The Sound Department
http://www.soundepartment.com/
http://www.imdb.com/name/nm0362504/
_______________________________________________
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