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.
Resize Cocoa windows proportionally
Asked Answered
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];
}
You don't resize applications, you resize windows. You can use -[NSWindow setContentAspectRatio:]
.
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.
nil
– Ruebenrueda