ios - 自动布局 : Set height View depends on other height View

标签 ios swift autolayout

我需要在我的布局中实现 AutoLayout。下面是一些截图:

1.

enter image description here

2.

enter image description here

案例是:

我在 ViewUITableView 中有一个 ShinobiDataGrid。第一张图片是第一个条件,在第一张图片中,我希望 view 的高度与 View Controller 的高度相同。

第二张和第三张图是有可用的TableView的时候。我希望 TableView 始终位于 View Controller 的底部并且 View 的高度取决于高度 Table View.

我读了this , this以及所有相关引用,但它对我不起作用。

编辑

我读了一些关于自动布局的文章,我在下面得到了这个:

1.

enter image description here

2.

enter image description here

但在第一张图片中,UIView 与主视图仍有距离。我希望它离主视图底部只有 3 或 4 个点,如下所示:

enter image description here

现在,我有一个从 UIView 到 UITableView 的约束。我使用自定义优先级、常量等从 UIView 添加一个约束到底部主视图,但它不起作用。

最佳答案

1.我建议您使用带页眉和页脚的 UITableView,不要滚动。将您的 View 添加到 UITableViewCell。根据您的要求使用自定义单元格填充您的 UITableView。

2.您也可以使用 UIStackView。将所有 View 和 TableView 添加到 Interface Builder 中的垂直堆栈 View 。保持分布均匀。第一次隐藏你的 UITableView。您的 View 将覆盖完整然后在需要时显示/隐藏 TableView 并更新堆栈 View 。 相对于堆栈 View 限制您的 View 和 TableView 。 UIStackView 管理自动布局。

3.我会使用 UITableViewController 和静态单元格(没有滚动), View 和 TableView 作为静态 UITableViewCells 的 subview 。第一次在 heightFoRowAtIndexPath 中传递完整的高度。 tableview 何时可见。重新加载 tableview Controller 并相应地传递高度。

而不是在单元格内使用 UITableView。我建议使用 UIStackView 作为 subview 单元格。在 UIStackView 中显示您的数据。

关于ios - 自动布局 : Set height View depends on other height View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45292857/

相关文章:

ios - 如何将按钮移动到随机位置? ( swift )

ios - NSTimer 的最大时间间隔

ios - 具有嵌套表格 View 的静态表格单元格的动态高度

ios - 如何使用 Swift 以编程方式添加约束

iOS 模拟器自定义位置问题

iOS - 在运行时调整 UIScrollView 内容的大小

iphone - 如何隐藏数字小键盘?

ios - 有没有办法用一个 UICloudSharingController 创建多个 CKShares?

ios - 使用 AFNetworking 加载离线缓存的 JSON

ios - 从 Tableview 更新 Viewcontroller 中的标签文本