ios - 自动布局 : Pin top of view to bottom of another view programatically

标签 ios autolayout constraints

我正在将我的 XIB 文件切换到自动布局并遇到了这个问题,我似乎找不到关于堆栈的好答案。

我希望以编程方式将一个 View 的顶部固定到另一个 View 的底部。本质上,顶 View 将底 View 向下推,导致底 View 的高度按比例减小,同时保持锚定在底部。

顶 View 是固定高度,而底 View 是可变的。在伪代码中,我基本上想要这个:

If the top view is present, pin the top portion of the bottom view, to the bottom of the top view while being anchored at the bottom (or reduce height to compensate for the top view)

Otherwise, the bottom view will be displayed at full height, essentially height = top view + reduced height bottom view 

这需要以编程方式完成,因为顶部 View 仅有条件地显示,否则我希望底部 View 占据顶部 View 引入的高度。

希望这是有道理的!

最佳答案

如果您的 self View 具有属性 topViewbottomView,您可以这样做:

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_topView]-[_bottomView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_topView, _bottomView)]];

将顶 View 的高度设置为零也可以回答您隐藏的问题。

关于ios - 自动布局 : Pin top of view to bottom of another view programatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243328/

相关文章:

c# - 更改呈现 View Controller 约束

ios - Swift - 向 UIContainerView 添加约束使容器消失

ios - 我的聊天系统看起来有点奇怪,无法获得单元格的动态高度

ios - UITextView 放置在自动布局中表现得很奇怪

ios6 - 使用 Cocoa Auto Layout 将两个按钮居中

ios - 使用tableview时如何删除安全区域?

ios - 如何快速修复横向模式下的约束?

objective-c - UIScrollView:处理动态内容?

ios - 水平滑入式菜单

ios - Facebook 登录 Swift iOS 10 - 没有任何效果