简体   繁体   中英

How can I move across two child view controllers with autolayout?

I'm making a view controller with a left sidebar container view and a main container view that is a navigation controller.

Here's a picture of it: 在此处输入图片说明

I'm using autolayout so I may only use constraints.

How can I make the screen show only part of this view controller? I can't change the frame because I'm using autolayout...

First, try just adjusting the frame of your containing view (the one holding those two containers) to move it left.

In theory it's just [rightContainerView superview]

If that isn't working for you, you can always iterate through the constraints that are set on either view and remove/adjust them until you get the layout you want. You can hold on to the constraints you remove in an array on your view controller, then add them back when you want it to be restored.

See [view constraints]

You just adjust the constant parameter of a constraint. So you would want your two container views to have constraints to the top and bottom of the superview. The right container should be pinned to the right side of the superview, and have a 0 length constraint from its left side to the right side of the left container view (but no fixed width). Give the left container view a constraint to the left edge of the superview and a width constraint. That should give you sufficient constraints to define your starting point. Make an IBOutlet to the left container view's constraint to the left edge of the superview (lets call it leftCon). Then when you want to move that left container view off screen to the left, change its leftCon constraint's constant value:

self.leftCon.constant = -200; // this will move it 200 point to the left, and the right view will expand by 200 points.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM