Re: Move views relative to other view with Autolayout
Re: Move views relative to other view with Autolayout
- Subject: Re: Move views relative to other view with Autolayout
- From: Doug Hill <email@hidden>
- Date: Thu, 10 Mar 2016 15:16:10 -0800
> On Mar 10, 2016, at 1:35 PM, Ken Thomases <email@hidden> wrote:
>
> On Mar 10, 2016, at 3:21 PM, Doug Hill <email@hidden> wrote:
>>
>> I can see that people use multiple constraints when moving between different layouts. But what I don’t get is how there can be an alignment constraint that doesn’t cause a layout update when views move? How does autolayout decide to use the constraint when originally laying out the view but ignores it when the view layout changes? Apparently I don’t understand this very well but the docs don’t seem to go out of their way to describe this difference either.
>
> When using auto layout, the auto layout engine _determines_ the layout from the constraints. You can't change the layout other than by changing the constraints. You should not move a view by setting its frame or bounds or whatnot. If you do, the change will only be undone on the next layout pass, anyway. The "current" position of views is not an input to the auto layout system. The position of all views is an _output_ from that system.
>
> Regards,
> Ken
Ken,
Thanks for the info, that really does explain it. I guess the biggest problem I have with autolayout is I know a view layout I want, but trying to come up with the constraints to produce that layout is non-obvious in most cases. It would be nice if one could use a final view state as the input to the layout engine and have it come up with the constraints that will produce it. I also understand this is probably not an easy problem to solve but still…
Given this, I’m now working on a new solution to moving my views together. Instead of aligning the origin of my views to the container or each other, I create another view for alignment. I then set the origin of the alignment view (e.g. leading) by autolayout constraints to the superview. Then my other views set alignment constraints to this view. I then change the leading constraint on the alignment view and the other views move with it. This allows me to change one constraint value and cause the other views to update automatically.
Thanks again for the responses.
Doug Hill
_______________________________________________
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