Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 3, 2011, 12:00 PM   #1
rossipoo
macrumors regular
 
Join Date: Jun 2009
Resizing window with aspect ratio and a fixed border

I am trying to make my window resizable with an aspect ratio, and have a fixed border. I've tried a few different methods: the aspectRatio, and contentAspectRatio properties of NSWindow, an NSLayoutConstraint to set the height of a subview proportional to its width, and a custom windowWillResizeToSize method.

The aspectRatio and contentAspectRatio properties can't account for a fixed border. The aspect ratio will be different when the window is small than when it is large.

windowWillResizeToSize works only for diagonal resizing, and when resizing the window SMALLER horizontally and vertically. There is no way to tell what corner or side is being resized, and even if that were possible, it's not appropriate to return a size larger than the proposed size when doing a horizontal or vertical resize.

NSLayoutConstraint seems to be the best in theory, but it seems to be broken when resizing horizontally from the sides of the window, resizing is just stuck when resizing horizontally. Corners and vertical resizing does resize the window as expected.

This is my code for the constraint. Does anyone have any suggestions?

Code:
	NSLayoutConstraint *constraintHeight = [NSLayoutConstraint constraintWithItem:_customView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:_customView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
rossipoo is offline   0 Reply With Quote
Old Nov 4, 2011, 12:12 AM   #2
rossipoo
Thread Starter
macrumors regular
 
Join Date: Jun 2009
To clarify, here is a diagram of the window. I want the highlighted subview to be maintained at a certain aspect ratio, and I also want to have a fixed border around the content that is not part of the aspect ratio calculation.

As indicated, when I am using the NSLayoutConstraint code above, the window will resize vertically by dragging the top and bottom edges of the window, but dragging the side edges results in nothing happening. I have tried turning the constraint around: height=width to width=height, and I have tried using both together, but the behavior is the same regardless.

Could this be a bug with the constraint system?



Uploaded with ImageShack.us
rossipoo is offline   0 Reply With Quote
Old Dec 17, 2011, 08:35 AM   #3
pieceOfHumans
macrumors newbie
 
Join Date: Oct 2011
I have noted many -did routines in Mac OSX are predictably unreliable. The unreliability of them also changes from upgrade to upgrade in attempt to fix the issues. I steer away from them as only CoreData seems to be solid.

Try using NSWindow-setContentAspectRatio:

Good Luck

Last edited by pieceOfHumans; Dec 17, 2011 at 08:40 AM.
pieceOfHumans is offline   0 Reply With Quote
Old Dec 17, 2011, 11:21 AM   #4
Kenndac
macrumors regular
 
Join Date: Jun 2003
The following works perfectly for me:

Code:
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
	return NSMakeSize(frameSize.width, frameSize.width);
}
If you need to figure out whether the user is resizing horizontally, vertically, or both, compare [sender frame].size with frameSize.
Kenndac is offline   0 Reply With Quote
Old Dec 17, 2011, 08:39 PM   #5
rossipoo
Thread Starter
macrumors regular
 
Join Date: Jun 2009
Actually, you can't tell what direction the user is resizing by comparing the frame. There is no way to differentiate between the user dragging from the bottom edge straight down, and from one of the corners straight down.
rossipoo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Microphone and Bootcamp FIX .md Windows, Linux & Others on the Mac 3 Sep 6, 2012 08:15 PM
Running windows on both Parallels and Boot Camp? Smatts123 Mac Applications and Mac App Store 1 Jul 3, 2011 10:58 PM
MBP, Windows 7, rendering/photography and heat... legreve MacBook Pro 1 Mar 5, 2011 11:32 PM
Apple Releases iTunes 10.0.1 With Ping Sidebar and Bug Fixes MacRumors MacRumors.com News Discussion 270 Oct 26, 2010 01:23 PM
Installing Windows with Boot Camp and partitions calrockx Windows, Linux & Others on the Mac 2 Dec 22, 2008 10:52 PM


All times are GMT -5. The time now is 07:23 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC