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: Quincey Morris <email@hidden>
- Date: Thu, 10 Mar 2016 13:15:11 -0800
- Feedback-id: 167118m:167118agrif8a:167118sBls6ic8yr:SMTPCORP
On Mar 10, 2016, at 12:59 , Doug Hill <email@hidden> wrote:
>
> I set up an auto layout constraint so that an another view is a fixed number of pixels from the side view. I then want to move the origin of the side view and have the other view move with it.
>
> If I set up an alignment constraint so trailing space from my first view to the side view is a fixed number of pixels. Let’s say 20 pixels. When I move the origin of the side view, the first view doesn’t keep the 20 pixel spacing. In fact does nothing.
Isn’t the issue what constraints you’ve put on the side view?
When using autolayout, you can’t “move the origin” of a view, except by adjusting constraints programmatically. You have to come up with a set of constraints that describes the relationship of the views in both configuration (side view visible or not). You might be able to do this by adding conflicting constraints to the first view (trailing to side view, trailing to superview), then enable one constraint and disable the other. To change configurations, toggle both enable properties and setNeedsLayout.
The easy way to do this, of course, is to use a horizontal stack view (NSStackView, UIStackView), since that handles hiding and showing of views without explicit constraints. NSStackView has been around since OS X 10.9 but real autolayout compatibility only came in 10.11, UIStackView has been around since iOS 9.0.
_______________________________________________
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