2017-08-02 34 views
1

我有UIScrollview裏面有動態視圖(標籤,Imageview)。我隱藏了一些意見,但白色的空白空間在那裏。我怎樣才能刪除它?在滾動視圖中隱藏視圖後刪除空白區域?

我試着用下面的代碼,但它不工作,

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]]; 

文件。類似的佈局:

-View 

-ScrollView 

    -UIImageView 

    -UIButton 

    -UIButton 

    -UILable 

    -UILable 

    -UIButton 

    -UILable 

    -UILable 
+1

可以提供任何截圖刪除不需要的滾動視圖的看法? –

+0

使用此[layoutsubviews](https://developer.apple.com/documentation/uikit/uiview/1622482-layoutsubviews),並在此方法中更改您的約束。如果沒有幫助,請在[layoutIfNeeded](https://developer.apple.com/documentation/uikit/uiview/1622507-layoutifneeded)中嘗試。它會幫助你。 –

+0

請使用滾動視圖下的視圖以及該視圖中的所有其他對象。 –

回答

0

只是躲在意見不會幫助,因爲它仍然會發生。你有幾個選擇: 1. scrollView中的每個視圖都應該有高度約束,當需要隱藏時應該設置爲0。然後,你應該叫

[scrollView setNeedsLayout]; 
[scrollView layoutIfNeeded]; 
  • 你可以通過調用
  • [viewToHide removeFromSuperview];

    +1

    謝謝您的回答。如果我使用[viewToHide removeFromSuperview]; 它會刪除空間@CrazyJoeLv –

    相關問題