Re: Setting the content origin in IB
Re: Setting the content origin in IB
- Subject: Re: Setting the content origin in IB
- From: Uli Kusterer <email@hidden>
- Date: Mon, 5 Feb 2007 08:14:06 +0100
Am 02.02.2007 um 10:15 schrieb Ken Tozier:
The content view contains a grid of page icons that "flow" as the
view is widened/narrowed. If the view is narrowed beyond a certain
threshold, the content view flows pages to a new row and updates
the frame size to reflect the new depth. What I expect to happen is
that the title bar would stay put and the content view would get
deeper. What actually happens is that the content view does get
deeper but instead of growing in a downward direction, the bottom
stays put and title bar moves up.
It's pretty simple, actually: The origin is always in the
*containing* view's coordinates. So, isFlipped doesn't apply to it.
So, either you wrap everything in another flipped view, or you simply
do a little maths.
The maths is fairly easy: If you enlarge your view rect's height or
width, the origin (the *bottom* left corner) usually stays put. Since
you want the view to grow downwards, you want the *top* left corner
to stay put. You do that by moving down the origin by the amount the
view became larger:
float amountToGrow = newHeight -myRect.size.height;
myRect.size.height += amountToGrow;
myRect.origin.y -= amountToGrow;
If it helps, you can also calculate the coordinates of each corner of
the rect, and then move the bottom two corners and create a new rect
from that:
float left, top, right, bottom;
left = myRect.origin.x;
bottom = myRect.origin.y;
right = left +myRect.size.width;
top = bottom + myRect.size.height;
bottom -= amountToGrow;
myRect.origin.x = left;
myRect.origin.y = bottom;
myRect.size.width = right - left;
myRect.size.height = bottom -top;
That's pretty much all that's needed. There is simply no provision in
Cocoa to change a view's origin. You can anchor a view using the
springs on the "Size" pane in IB's inspector and it will be
positioned relative to something else than the origin if you want,
but the origin is the origin. If you flip you can work around this a
little, but as the view's frame is in the containing view's
coordinate system, you'd have to mandate a flipped container view,
which restricts you a good deal.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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