2017-07-19 137 views
1

我面臨約束自動佈局問題,這是我有一個UITableView在上部和UIView在較低。當UITableView展開tableView部分時,我想讓底部的UIView自動向下移動,當摺疊tableView部分時,底部的UIView會自動向上移動。約束uitableview和uiview自動佈局

enter image description here

下面是我的故事板設計,綠色部門的UITableView,上衝部門的UIView。

enter image description here

You can get my code from here

你的幫助是非常讚賞。

+0

廣東話,你只是使你的UIView實現代碼如下(小區或者頁腳視圖)的一部分,那麼它將會與其他表視圖細胞 – Tj3n

+0

@ Tj3n轉移其實下面還有一些其他的UIView。 –

+0

@NurII是不是它會自動調整,當你在部分(擴大)添加一行?只要你的底部視圖的頂部是在桌面底部刷新的 – Joshua

回答

0

添加您的tableview的高度約束IBOutlet。

enter image description here

控制+拖放到視圖控制器。你會得到這樣的財產。

@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]; 
+0

錯誤在於「@property(nonatomic,strong)NSLayoutConstraint * tableviewHeightConstraints;」而不是「@property(nonatomic,strong)IBOutlet NSLayoutConstraints * tableviewHeightConstraints;」 ? –

+0

是的。更新。請立即檢查。你設法讓它起作用嗎? – Balasubramanian

+0

嗨巴拉,它得到了迴應。但是,當我點擊展開&摺疊部分。結果變得相反。我已經將我的代碼上傳到這個鏈接,你能幫我看一下嗎?https://drive.google.com/open?id=0B3e7l6RGD-rnMmFDZi1LOS1MMkU –

0

嘗試使用​​: title1,title 2 ...是tableview標題部分。當展開numberofRowinsection = 1和= 0時崩潰 - 您的uiview是可用視圖單元格的部分。
點擊部分視圖時重新加載部分。

-2

別擔心,快樂。我爲你制定了一個解決方案。關於你的佈局只是簡單的思維和流動以下陡:

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

+1

但這不是iOS –