Re: NSWindow - how to resize it keeping aspect ratio?
Re: NSWindow - how to resize it keeping aspect ratio?
- Subject: Re: NSWindow - how to resize it keeping aspect ratio?
- From: Alexander Bokovikov <email@hidden>
- Date: Thu, 25 Feb 2010 17:04:10 +0500
On 25.02.2010, at 15:17, Ariel Feinerman wrote:
there is of the matter is that -setAspectRatio: sets the window`s
aspect ratio, but when window has been loaded from nib and not
resized yet, its size is taken from "content size" that was written
in IB with it own aspect. Then when window has been resized it
instantly get size to conform aspect. Can you suggest something?
In general I don't care about IB settings overriding, as my window
initially has correct aspect ratio. The only my care was about its
manual resizing at runtime. Don't know if this a correct solution or
not, but I've written this code:
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
NSRect r;
r = NSMakeRect([sender frame].origin.x, [sender frame].origin.y,
frameSize.width, frameSize.height);
r = [sender contentRectForFrameRect:r];
r.size.height = r.size.width * 422 / 674;
r = [sender frameRectForContentRect:r];
return r.size;
}
And it works perfectly for me. 674 x 422 - is my original content view
size, defined in IB. Unfortunately IB operates by window's content
view size, whereas the message above operates by window's frame size,
which is not the same. Therefore it's required to recalculate the size
between window frame and content view sizes, if we have a care about
content view aspect ratio keeping.
Thanks.
_______________________________________________
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