Re: Window resizing with animation
Re: Window resizing with animation
- Subject: Re: Window resizing with animation
- From: Greg Titus <email@hidden>
- Date: Tue, 19 Aug 2003 10:10:45 -0700
On Tuesday, August 19, 2003, at 09:27 AM, Jesus De Meyer wrote:
I'm trying to implement a window with a toolbar, when you click on a
toolbar item the window changes its content view and should resize so
that the content view is fully visible. However, with the code I wrote
(see below) the window resizes AND moves. The resize isn't correct
either. What am I doing wrong?
[window setContentView:subView];
[window setFrame:[subView bounds] display:YES animate:YES];
Two things:
1) The size you are setting it to is too small. The window size has the
title bar and toolbar in it in addition to the content view, and you
are just setting it to the size of the content view.
You need to call:
newFrame.size = [NSWindow frameRectForContentRect:[subView frame]
styleMask:[window styleMask]].size;
... to get the right size.
2) The position you are setting it to is wrong. The subView bounds
origin in the window is a completely different coordinate system from
the window origin on screen. These are almost never going to match. You
want to take the window's current top-left point and maintain it by
setting the y coordinate to the current frame's maxY minus the new
height. (Assuming you want the window to grow and shrink from the
bottom while the title bar remains in the same place.)
Like so:
newFrame.origin = NSMakePoint(NSMinX([window frame]), NSMaxY([window
frame]) - NSHeight(newFrame));
Put together, this code should do what you want:
NSFrame newFrame;
[window setContentView:subView];
newFrame.size = [NSWindow frameRectForContentRect:[subView frame]
styleMask:[window styleMask]].size;
newFrame.origin = NSMakePoint(NSMinX([window frame]), NSMaxY([window
frame]) - NSHeight(newFrame));
[window setFrame:newFrame display:YES animate:YES];
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.