2017-08-09 62 views
0

我剛剛開始學習Swift Developing iOS Apps (Swift)教程。我創建這個自定義級別控制但每次我運行的應用程序是時間發送如下因素錯誤:XCode Swift:爲什麼它打破了我的約束?

2017-08-09 15:49:41.894597+0200 FoodTracker[5051:2273797] [LayoutConstraints] 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. 
(
    "<NSLayoutConstraint:0x17409af90 UIButton:0x100c12d90.width == 44 (active)>", 
    "<NSLayoutConstraint:0x17009c160 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.leading == UIButton:0x100c12d90.leading (active)>", 
    "<NSLayoutConstraint:0x17009c200 'UISV-canvas-connection' H:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400)>", 
    "<NSLayoutConstraint:0x17009bee0 'UIView-Encapsulated-Layout-Width' FoodTracker.RatingControl:0x100c02400.width == 343 (active)>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17409af90 UIButton:0x100c12d90.width == 44 (active)> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
2017-08-09 15:49:41.895770+0200 FoodTracker[5051:2273797] [LayoutConstraints] 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. 
(
    "<NSLayoutConstraint:0x17409af40 UIButton:0x100c12d90.height == 44 (active)>", 
    "<NSLayoutConstraint:0x17009c250 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.top == UIButton:0x100c12d90.top (active)>", 
    "<NSLayoutConstraint:0x17009c340 'UISV-canvas-connection' V:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400)>", 
    "<NSLayoutConstraint:0x17009bf30 'UIView-Encapsulated-Layout-Height' FoodTracker.RatingControl:0x100c02400.height == 50 (active)>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17409af40 UIButton:0x100c12d90.height == 44 (active)> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

我設置按鈕寬度的限制== 44和按鈕的高度== 44,但沒有其他的限制。我按照教程中的描述做了一切,並且不知道爲什麼它不起作用。我檢查了所有可以找到的約束條件,但我不確定是否全部都是因爲我對Xcode不太熟悉。有沒有人有線索如何解決這個問題?

This is how it should look like: Apples Result But this is how it looks: My Result (Only The Red Area is important)

Thx for your Help!

尼科

+0

是紅色正方形/長方形一個UIButton或一個UIView? – DonMag

+0

StackView中的UIButton。 –

+0

啊 - 好吧,我只是看看你正在跟隨的教程.... StackView本身是一個*垂直* StackView中包含其他元素?如果是的話,是*那* StackView的'Alignment'設置爲'Fill'? – DonMag

回答

0

基於錯誤信息,我想你已經嵌入UIStackView裏面的按鈕。堆棧視圖具有不正確的約束,或者根本沒有約束,並且正在使用自動調整掩碼。堆棧視圖的大小爲343x50,並強制按鈕匹配。

+0

所有的建議是正確的。我沒有設置堆棧視圖的任何約束。但是編寫教程的人也沒有......(他們是來自蘋果的Aud,所以它應該是我想的..)我必須做什麼才能將Button解除綁定到堆疊視圖的大小?只需爲堆棧設置自己的約束? –

+0

你需要堆棧視圖嗎? –

+0

將會有5個按鈕應該彼此相鄰(水平)。所以我覺得我需要它?我真的不知道,我想學習它:D –

0

看起來像你有一個UIStackView。將UIButton從UIStackView中移出,並將UIButton的頂部約束設置爲與您在UIStackView中定義的相同間距,並將UIButton的前端對齊設置爲UiStackView,並且您很好

+0

好的,但我不想將按鈕移出堆棧視圖。教程應該學會如何使用堆棧視圖,所以我不想圍繞它們工作。 –

+0

你應該閱讀一下UIStackView的目的是什麼。就我個人而言,如果我想在它內部的所有視圖中使用相同的約束條件,我會使用它你顯然不希望UIButton有相同的約束。所以它應該在UIS​​tackView之外。把它拿出來不會讓你對UIStackView的瞭解更少 – hooliooo

+0

我不想讓這個按鈕的堆棧視圖有相同的Constants,但是在這個堆棧視圖中將會有5個按鈕應該有所有相同的約束條件並且放在每個按鈕旁邊其他(horizo​​ntaly)..我認爲這是一個堆棧視圖的目的。讓多個對象相鄰。 –

0

我找到了原因和解決方案。

水平堆棧視圖 - 通過垂直和水平填充整個自己的內部空間。這意味着 - 水平堆棧視圖將設置內部項目的高度和緯度以填充所有可用空間。

只有消除這些警告,我發現路 - 設置寬度/的水平疊層觀的高度與/所有內部元件的高度完美契合:252x44

相關問題