2015-03-25 52 views
0

我試圖在uiview的下邊距和滾動視圖的下邊距之間設置編程約束。然而,xcode給了我一些錯誤,文本看起來最好不合適,有時它並不出現Swift編程約束下邊距不起作用

所以基本上我有一個尺寸爲400的uview,並將父視圖作爲滾動視圖。 我想在滾動視圖底部和uiview底部之間添加300的距離。我需要以編程方式執行此操作,因爲無法確定屏幕上給定時間將顯示多少視圖,因此我需要以編程方式更改它們之間的約束。

我的代碼是

view.addConstraint(NSLayoutConstraint(
      item:container1, 
      attribute:NSLayoutAttribute.Bottom, 
      relatedBy:NSLayoutRelation.Equal, 
      toItem:scrollFrame, 
      attribute:NSLayoutAttribute.Bottom, 
      multiplier:0, 
      constant:400) 
     ) 

但它不工作......顯然,在模擬器,UIView的從頂部,或者說定位在400,因爲它的動作下來的時候我增加恆壓(試600)

的Xcode打印以下錯誤:

2015-03-25 12:38:13.342 GraficTest[6612:707546] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7be906b0 V:|-(48)-[UIView:0x7be8e780] (Names: '|':UIScrollView:0x7be90340)>", 
    "<NSLayoutConstraint:0x7bfd80e0 V:[UIView:0x7be8e780(257)]>", 
    "<NSLayoutConstraint:0x7bf6a940 UIView:0x7be8e780.bottom == + 600>" 
) 

你能幫幫我嗎?

非常感謝!

回答

1

從錯誤信息,我可以推斷出幾件事情:

  1. 有放置的UIView從UIScrollView的頂部48點約束
  2. UIView的有257點
  3. UIView的底部高度約束必須放在UIScrollView底部以上600點。

如UIScrollView中會有一些高度讓我們說X,從上述約束它應該是

X = 48 + 257 + 600 = 905

但這顯然並非如此,因此佈局系統無法滿足所有的限制條件。

通過從UIView中刪除高度約束,您可能可以解決問題。

+0

非常感謝,這樣做! – 2015-03-25 13:02:52