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?
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];