|
|
#1 |
|
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]; |
|
|
|
0
|
|
|
#2 |
|
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 |
|
|
|
0
|
|
|
#3 |
|
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. |
|
|
|
0
|
|
|
#4 |
|
The following works perfectly for me:
Code:
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
return NSMakeSize(frameSize.width, frameSize.width);
}
|
|
|
|
0
|
|
|
#5 |
|
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.
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 02:40 PM.







Linear Mode

