Re: Quickie about constraints
Re: Quickie about constraints
- Subject: Re: Quickie about constraints
- From: Charles Srstka <email@hidden>
- Date: Sun, 17 Aug 2014 21:29:28 -0500
On Aug 17, 2014, at 8:39 PM, Roland King <email@hidden> wrote:
>>
>> On 18 Aug 2014, at 9:10 am, Charles Srstka <email@hidden> wrote:
>>
>> 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:
>
> It says exactly that - you quote it here
>
>
>>>
>>> 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)].
>
> and further up ...
>
> "When this property is YES, which it is by default, the autoresizing mask of a view is translated into constraints.".
>
> So as you can see I'm talking about the case where translatesAutoresizin... is left at YES. The autoresizing mask is turned into constraints and the constraints thus generated are supposed to be adjusted if you call setFrame:
>
>
>>
>> This section mentions that you can use -setFrame: when the translatesAutoresizingMaskIntoConstraints property is YES.
>
> Yes I know that - that's exactly what I was talking about. When I first started using autolayout and read that paragraph I left that property as YES and tried adjusting frames. I failed to make it work consistently at the time.
If you're using autolayout, the views in your nib file will have their translatesAutoresizingMaskIntoConstraints property set to NO. The only views that would have that property set to YES would be views you created and/or added to the view tree manually. The subviews of such views should be manipulable via autoresizing masks and -setFrame: — and indeed, if they didn't, we'd probably see lots of failures all across the board in any UI code that was written before autolayout was introduced, probably including many AppKit view classes, because all of that code depends on the legacy behavior.
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