SOLVED Re: How to get max size of view according to constraints?
SOLVED Re: How to get max size of view according to constraints?
- Subject: SOLVED Re: How to get max size of view according to constraints?
- From: Charles Srstka <email@hidden>
- Date: Tue, 20 Mar 2012 18:59:58 -0500
Sweet! I’ve found the solution to my own problem. Here it is, in case someone else finds this thread wondering the same thing.
What I was trying to do was to keep track of the NSScrollView being resized, and adjust the size of its document view as needed. Toward this end, I was trying to determine the min and max allowed size, grab the scroll view’s documentVisibleRect, adjust the size to avoid angering the constraint gods, and then set the frame on the document view.
I had figured the solution to this would be something fairly simple and embarrassing, and sure enough it was. During a rewatching of the WWDC 2011 video on Cocoa Auto Layout in order to figure out the cause of some other weird bugs I was seeing, I noticed something I’d glossed over before: when using constraints, you are not supposed to call setFrame: on any of your views, but are instead supposed to set constraints that tell the autolayout system what the position and size should be. And of course, once I set about doing that, I remembered that these constraints can have priorities — so, all I had to do was to set the width and height to what I wanted them to be with their priorities set to NSLayoutPriorityDragThatCanResizeWindow, and all’s well! The view gets the size I tell it if it’s legal, and adjusts it if it’s not. Perfect.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden