Resize Cocoa windows proportionally
Asked Answered
B

2

6

I was wondering how I could constrain an application window to be resized only proportionally? I want it to keep the ratio so as not to distort photos/videos.

Belonging answered 13/3, 2011 at 17:40 Comment(0)
J
10

You would probably do this in your application delegate; in a standard project template, that object has a reference to your app's main window.

- (void)awakeFromNib {
    // Keep the aspect ratio constant at its current value
    [window setAspectRatio:window.frame.size];
}
Joyance answered 9/4, 2011 at 8:13 Comment(1)
Note to self: This answer is 100% right. Depending on how you get your reference to window, make sure it's not nilRuebenrueda
C
5

You don't resize applications, you resize windows. You can use -[NSWindow setContentAspectRatio:].

Carnival answered 13/3, 2011 at 17:44 Comment(5)
Thanks for the rectification. Where do I declare this paramater?Belonging
Whenever you know what the aspect ratio will be, maybe in the window controller or document controller, depending on how your application is organized.Carnival
I am very new to xcode and objective-c, excuse my ignorance :) I created the window on the .xib file via the visual editor, so i dont know where to put that code.Belonging
Well, typically when you have a document window in a .xib file you'll have a "file's owner" object which is often a window controller. Before you can set the window's aspect ratio you need to know what the aspect ratio of your content is. Sounds like you might want to get a good introductory Cocoa book and do some reading before you write any more code though...Carnival
I ordered one, still waiting for it, but i thought i might try anyways before. So now i have a window controller file, which is a subclass of NSWindow. The aspect ratio of my content is 4/3.Belonging

© 2022 - 2024 — McMap. All rights reserved.