Re: Quickie about constraints
Re: Quickie about constraints
- Subject: Re: Quickie about constraints
- From: Charles Srstka <email@hidden>
- Date: Sun, 17 Aug 2014 20:10:35 -0500
On Aug 17, 2014, at 7:13 PM, Roland King <email@hidden> wrote:
> .. and I finally found the one piece of the autolayout adoption guide which made me think back in the day I could use setFrame: and it would all work nicely.
>
> https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AdoptingAutoLayout/AdoptingAutoLayout.html#//apple_ref/doc/uid/TP40010853-CH15-SW1<https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AdoptingAutoLayout/AdoptingAutoLayout.html#//apple_ref/doc/uid/TP40010853-CH15-SW1>
>
> This tells you that not only are constraints set up for you based on the autoresizing mask but they are also adjusted for you as you call setFrame:
No, it doesn't. Here are the references to -setFrame: on that page:
> Views that are aware of Auto Layout can coexist in a window with views that are not. That is, an existing project can incrementally adopt Auto Layout—you don’t have to make it work in your entire app all at once. Instead, you can transition your app to use Auto Layout one view at a time using the property translatesAutoresizingMaskIntoConstraints.
>
> *** When this property is YES *** [emphasis mine], which it is by default, the autoresizing mask of a view is translated into constraints. For example, if a view is configured like the one below, and translatesAutoresizingMaskIntoConstraints is YES, then the constraints |-20-[button]-20-| and V:|-20-[button(20)] are added to the view’s superview. The net effect is that unaware views behave as they did in versions of OS X prior to version 10.7.
>
> If you move the button 15 points to the left (including by calling setFrame: at runtime), the new constraints would be |-5-[button]-35-| and V:|-20-[button(20)].
This section mentions that you can use -setFrame: when the translatesAutoresizingMaskIntoConstraints property is YES.
Then, later on:
> If you have a view that does its own custom layout by calling setFrame:, your existing code should work. Just don’t call setTranslatesAutoresizingMaskIntoConstraints: with the argument NO on views that you place manually.
This section specifically states that if you want to use -setFrame: yourself, you should make sure *not* to set translatesAutoresizingMaskIntoConstraints to NO (i.e., leave it set to YES).
This is consistent with the behavior, which is that -setFrame: only has meaning when you are not using the constraints system, which is when translatesAutoresizingMaskIntoConstraints is set to YES.
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