1
votes

I'm running into a weird issue with my code and I hope someone else has better ideas on how to handle this.

**Summary of what I want to achieve: **

I have an editor that looks like this: On the right side I have an inspector panel where I can manually change the frame of the currently selected view (which sits inside another NSView that's the document view of an NSScrollView).

**Summary of implementation: **

The main view inside the NSScrollView doesn't directly use autolayout, because I need to be able to set the frame manually, I leave the translatesAutoresizingMaskIntoConstraints property to true (default value) for all the subviews inside the NSScrollView. So I end up with constraints automatically created when I set the frame.

The problem:

When I set the frame, to let's say (1, 0, 100, 100) for some reason the autolayout engine will take in account the magnification value of the NSScrollView and will readjust the frame, so the final frame might end up looking like (1.74, 0, 100, 100). While I do understand this, the question is, can I disable this behavior? Is it possible to have frame value increments of 1.0 while making sure Autolayout doesn't screw the final frame regardless of the NSScrollView magnification value?

Thank you!

1

1 Answers

1
votes

Autolayout views inside a magnified NSScrollView can give very strange values at times, and I haven't really figured out when and why.

I have approached a similar problem by adjusting the views' position manually according to magnification of superview, or by subclassing them and writing a method for them to take the magnification into account.

So, for example:

CGFloat factor = 1 / magnification;
element.frame = NSRectMake(x * factor, y * factor, ...);

Hope this helps.