Re: Quickie about constraints
Re: Quickie about constraints
- Subject: Re: Quickie about constraints
- From: Roland King <email@hidden>
- Date: Mon, 18 Aug 2014 09:39:54 +0800
> 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 <mailto: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><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.
>
> 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.
nowhere in *this* piece of my reply did I say otherwise, this was entirely about leaving the property set as YES. I merely pointed out the piece of documentation I had read a while ago which supported my view at the time, that you could use setFrame: in that instance. I also said it didn't work for me at the time because it didn't and also pointed out that I was on iOS at the time as it may make a difference (iOS uses setBounds and setCenter I think instead of setFrame).
>
> 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