约束uitableview和uiview自动布局
我面临约束自动布局问题,这是我有一个UITableView在上部和UIView在较低。当UITableView展开tableView部分时,我想让底部的UIView自动向下移动,当折叠tableView部分时,底部的UIView会自动向上移动。约束uitableview和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];
错误在于“@property(nonatomic,strong)NSLayoutConstraint * tableviewHeightConstraints;”而不是“@property(nonatomic,strong)IBOutlet NSLayoutConstraints * tableviewHeightConstraints;” ? –
是的。更新。请立即检查。你设法让它起作用吗? – Balasubramanian
嗨巴拉,它得到了回应。但是,当我点击展开&折叠部分。结果变得相反。我已经将我的代码上传到这个链接,你能帮我看一下吗?https://drive.google.com/open?id=0B3e7l6RGD-rnMmFDZi1LOS1MMkU –
尝试使用: title1,title 2 ...是tableview标题部分。当展开numberofRowinsection = 1
和= 0时崩溃 - 您的uiview是可用视图单元格的部分。
点击部分视图时重新加载部分。
别担心,快乐。我为你制定了一个解决方案。关于你的布局只是简单的思维和流动以下陡:
1.您的父母布局ConstraintLayout,
2.Secondly采取的RelativeLayout,
3.Then采取另一种ConstraintLayout和
4.最后加入你的“ ExpandableListView”和你的UI元素
你也可以看到下面的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#EACB3B"
tools:context="com.example.uitableview.MainActivity">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/lvID"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgView"
android:layout_width="wrap_content"
android:layout_height="234dp"
android:src="@drawable/mango"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/expLv"
app:layout_constraintHorizontal_bias="0.0" />
<ExpandableListView
android:id="@+id/expLv"
android:layout_width="352dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
或者你也可以流过的谷歌链接: https://drive.google.com/open?id=0B-yo9VvU7jyBUHN6RHVXQmUtVU0
但这不是iOS –
广东话,你只是使你的UIView实现代码如下(小区或者页脚视图)的一部分,那么它将会与其他表视图细胞 – Tj3n
@ Tj3n转移其实下面还有一些其他的UIView。 –
@NurII是不是它会自动调整,当你在部分(扩大)添加一行?只要你的底部视图的顶部是在桌面底部刷新的 – Joshua