限制uitableview和uiview的autolayout
我正面临一个约束自动布局问题,我在上面有一个UITableView,在下面有一个UIView。 当UITableView扩展tableView部分时,我希望底部的UIView自动向下移动,当折叠tableView部分时,底部的UIView将自动向上移动。
下面是我的故事板设计,绿色部门是UITableView,红色部门是UIView。
你可以从这里获取我的代码
非常感谢您的帮助。
添加tableview的高度约束的IBOutlet。
控制+拖放到视图控制器。 你会得到这样的财产。
@property (strong, nonatomic) IBOutlet NSLayoutConstraint * tableviewHeightConstraints;
每当你切换桌面视图时,都要调用它。 contentSize
将计算tableview高度并更新tableviewHeightConstraints
约束的高度。
CGFloat height = MIN(self.view.bounds.size.height, self.tableView.contentSize.height); self.tableviewHeightConstraints.constant = height; [self.view layoutIfNeeded];
尝试使用ViewForHeaderSection
:title1,title 2 …是tableview标题部分。 当展开numberofRowinsection = 1
并且= 0时崩溃 – 你的uiview是uitableview cell in section。
单击部分视图时重新加载部分。
别担心,快乐。 我已经为你找到了解决方案。 只需简单地思考一下你的布局并在下面陡峭流动:
1.您的父布局是ConstraintLayout,
2.其次采取RelativeLayout,
然后采取另一个ConstraintLayout和
4.最后添加“ExpandableListView”和UI元素
您还可以看到以下代码:
或者您也可以使用Google链接: https : //drive.google.com/open?id = 0B -yo9VvU7jyBUHN6RHVXQmUtVU0