我怎么能在两个子视图控制器移动与自动布局? [英] How can I move across two child view controllers with autolayout?

查看:132
本文介绍了我怎么能在两个子视图控制器移动与自动布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个视图控制器与左侧边栏的容器观点,这是一个导航控制器的主容器视图。

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...

推荐答案

您只需调整约束的常量参数。所以,你会希望你的两个集装箱的看法有约束的上海华的顶部和底部。右容器应固定在上海华的右侧,并具有从其左侧向左容器视图(但是没有固定的宽度)的右侧一个0长度约束。给左容器查看约束到上海华的左边缘和宽度约束。这应该给你足够的约束来定义你的出发点。使一个IBOutlet向左容器视图的约束至上海华的左边缘(可以称之为leftCon)。然后,当你要移动的左容器查看关闭屏幕的左侧,改变其leftCon约束的恒定值:

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.

这篇关于我怎么能在两个子视图控制器移动与自动布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆