2015-09-15 83 views
5

我讀過所有與此類似的SO問題,我很迷茫。我收到以下錯誤:這是在討論什麼佈局約束?

2015-09-14 22:59:40.455 guess-who[60143:9602686] 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:0x7c0f8e30 UIImageView:0x7b6efb60.top == _UILayoutGuide:0x7c0f67a0.top>", 
    "<_UILayoutSupportConstraint:0x7c0f8ae0 V:[_UILayoutGuide:0x7c0f67a0(0)]>", 
    "<_UILayoutSupportConstraint:0x7c0f0070 _UILayoutGuide:0x7c0f67a0.bottom == UIView:0x7c0f65e0.bottom>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6130 h=--& v=--& UIImageView:0x7b6efb60.midY == + 204>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6160 h=--& v=--& V:[UIImageView:0x7b6efb60(220)]>", 
    "<NSLayoutConstraint:0x7b6f6dc0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7c0f65e0(518)]>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6e20 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7c0f65e0] (Names: '|':UIView:0x7c0effc0)>" 
) 

Will attempt to recover by breaking constraint 
<_UILayoutSupportConstraint:0x7c0f0070 _UILayoutGuide:0x7c0f67a0.bottom == UIView:0x7c0f65e0.bottom> 

我已經得到了本作一堆,我已經成功地解決了其他方面的限制,但是這一個是絆倒了我。我不知道UILayoutSupportConstraint是什麼;文件不是很全面。我已經瀏覽了視圖調試器,並且UIView:0x7c0f65e0似乎是指我的主視圖(雖然由於某種原因,它是空白視圖的孩子?)。我無法找到任何與0x7c0f67a0有關的東西,儘管這似乎是指LayoutGuide,他們的底部必須是平等的。我不知道有什麼其他工具可以用來解決這個問題。

編輯:

使用View調試器,我已經將範圍縮小到這兩個約束條件,這兩者都不知道的來源之一:

enter image description here

我不能找到其中任何一個被設置。我知道每個人的第一個建議是將translatesAutoresizingMaskIntoConstraints設置爲false,但是這破壞了我的整個佈局,我不知道如何解決它。

+0

我可以看到你的整個項目嗎?這是關於自動佈局。 –

+0

我應該特別展示什麼? – thumbtackthief

+0

您的故事板。推它在github回購,所以我可以向你發送拉請求。 –

回答

-4

使用下面這行。這可能對你有所幫助。

[view setTranslatesAutoresizingMaskIntoConstraints:NO]; 
+0

我試過這個(當然,Swift等價物),它完全混淆了我的整個佈局。 – thumbtackthief

+2

這並不回答這個問題,它應該是一個評論。 – JAL

+0

再加上它沒有幫助,並且在Obj-C中。 – thumbtackthief

2

禁用translatesAutoresizingMaskIntoConstraints沉船佈局因爲其中的某些疊置元件沒有明確的高度/寬度集合(PlayAgain,貓,幀)並基於關閉圖像內容。

您的示例項目不能立即運行,因此我無法檢查運行時佈局。但是,我會首先指定這些元素的高度,以減少自動約束。它也看起來像是在運行時改變了很多約束,所以你需要對改變彼此衝突的約束保持謹慎。在開始約束常量擺弄之前,確保佈局的快樂!

8

你也可以考慮增加無障礙標識和約束識別你的意見,使您的AL記錄更清晰:

constraintVariableName.identifier = 「constraintVariableName」;

InterfaceBuilder下,使用標識屬性的檢查。

self.loginButton.accessibilityLabel = NSLocalizedString("LoginButtonAccessibilityLabel", @"");

這些ID的將在日誌中,比如你上面貼與IDS更換之類的UIView,和UIImageView的UIConstraint結束。

3

看來你已經給與Superview相關的圖像視圖給了約束。所以爲了滿足你對UILayoutGuide.bottom的約束,你的約束被打破了。正如你有增加了更多或不必要的限制

約束被越來越破碎是

  1. UILayoutGuide.top = UIView.top
  2. UILayoutGuide。高度= 0
  3. UILayoutGuide.bottom = UIView.bottom
  4. 的UIImageView高度約束
  5. 的UIImageView Y位置
  6. UIView的高度約束
  7. 你給的UIView從頂部垂直間距爲 '0' 但缺少底部/身高限制。

嘗試從1000改變的高度約束優先權750爲用的UIImageView高度(220),與UIView的高度(518)。

你也需要檢查底部約束爲 "<NSAutoresizingMaskLayoutConstraint:0x7b6f6e20 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7c0f65e0] (Names: '|':UIView:0x7c0effc0)>"

如果可能的話,那麼請附上混帳演示了更好的主意。

希望它有幫助。

+0

這很有幫助,但我看不到_where_約束條件3和4可能已被分配,或者如何找到它們以更改其優先級。我在ViewController中使用約束做了一些工作,但我沒有看到任何與之相關的東西。 (加上當他們被註釋掉時,我得到的錯誤) – thumbtackthief

+0

@thumbtackthief - 首先你需要選擇視圖。讓我們來考慮一下UIImageView Height的第四個約束。您只需選擇您的UIImageView,然後轉到xCode右側的「實用工具」面板,然後選擇「顯示大小檢查器」。在那裏你會發現你的觀點受到了限制。雙擊您想要更改優先級的約束。 –

+1

@thumbtackthief - 其次對於底部佈局指南,您需要檢查所有底部佈局指南。它將是一條直線水平線,或者您可以從已選擇2個約束的「文檔大綱」面板中選擇它。選擇一個約束,您可以在大小檢查器中看到它的常量值,優先級和乘數。 –