2016-08-01 121 views
-4

以下列表中的至少一個約束可能是您不想要的。試試這個:無法同時滿足約束條件?

  1. 看看每個約束,並試圖找出你不期望的;
  2. 找到添加不需要的約束或約束並修復它的代碼。

(注意:如果你看到NSAutoresizingMaskLayoutConstraints,你不明白,參考文檔爲UIView財產translatesAutoresizingMaskIntoConstraints

(
    "<NSLayoutConstraint:0x7fa0a385b5a0 H:|-(0)-[UIView:0x7fa0a3855f00] (Names: '|':UIView:0x7fa0a38588a0)>", 
    "<NSLayoutConstraint:0x7fa0a14c5dc0 H:[UIView:0x7fa0a3855f00]-(0)-| (Names: '|':UIView:0x7fa0a38588a0)>", 
    "<NSLayoutConstraint:0x7fa0a141e070 H:[UIView:0x7fa0a15274e0]-(80)-| (Names: '|':UIView:0x7fa0a3855f00)>", 
    "<NSLayoutConstraint:0x7fa0a141e0c0 H:|-(15)-[UIView:0x7fa0a15274e0] (Names: '|':UIView:0x7fa0a3855f00)>", 
    "<NSLayoutConstraint:0x7fa0a380c260 H:[UIView:0x7fa0a15274e0(305)]>", 
    "<NSLayoutConstraint:0x7fa0a16aa700 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fa0a38588a0(320)]>" 
) 

將嘗試打破約束 <NSLayoutConstraint:0x7fa0a380c260 H:[UIView:0x7fa0a15274e0(305)]>

恢復

UIViewAlertForUnsatisfiableConstraints上做一個符號斷點,以便在調試器中捕獲這個斷點。 <UIKit/UIView.h>中列出的UIConstraintBasedLayoutDebugging類別UIView中的方法也可能有所幫助。

+0

是啊,一個更多的是尋找同樣http://stackoverflow.com/questions/38692313/constraints-warning-in-console-i-am -not-able-to-understand –

+2

發佈您的約束代碼或屏幕截圖。 – Catoshi

+0

這些是約束錯誤,您需要刪除已添加的不需要的約束。 –

回答

0

這是我的經驗和解決方案。

選擇視圖(的UILabel,UIImage的等) 編輯>針>(選擇...),以上海華 編輯>解決自動佈局問題>添加缺少的約束

此錯誤是衝突的,你有約束之間添加。刪除不需要的約束。 小心,您不要在同一方向和類型上使用多個約束。

enter image description here 我會建議你使用SnapKit。這是一個Autolayout框架,使用非常方便。

import SnapKit 

var label = UILabel() 

label.snp_makeConstraints { (make) -> Void in 
    make.centerX.equalTo(0) 
    make.centerY.equalTo(0) 
    make.width.equalTo(30) 
    make.height.equalTo(30) 
} 

https://github.com/SnapKit/SnapKit 希望這是有益:)

相關問題