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

Similar Threads
thread Thread Starter Forum Replies Last Post
Dialog window sidebar resizing fixed in 10.9.3? Raunien OS X Mavericks (10.9) 0 May 15, 2014 05:54 PM
iPad: Video aspect ratio theromz iPad 13 Mar 13, 2014 04:53 PM
21:9 aspect ratio?? mobydick01 Mac mini 7 Jan 12, 2014 01:39 PM
What aspect ratio do you like to compose in? nateo200 Digital Video 15 Sep 16, 2012 06:56 PM
The New iPhone's aspect ratio dvir971 iPhone 1 Sep 8, 2012 05:37 PM

Forum Jump

All times are GMT -5. The time now is 11:23 AM.

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

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