剛剛開始學習iOS的自動版式,界面生成非常簡單的,但是當我試圖存檔同一件事上的代碼自動版式,無法同時滿足的約束
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(==2)-[_nextKeyboardButton]-(==2)-[_numPadButton]-(==2)-[_spaceButton]-(==2)-[_returnButton]-(==2)-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_nextKeyboardButton,_numPadButton,_spaceButton,_returnButton)]];
它拋出一個異常,
無法同時滿足約束條件。
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:0x6000000966c0 H:|-(2)-[UIButton:0x7fe4f1d1c760'Next'] (Names: '|':UIInputView:0x7fe4f1f04d00)>",
"<NSLayoutConstraint:0x600000096710 H:[UIButton:0x7fe4f1d1c760'Next']-(2)-[UIButton:0x7fe4f1d1d1d0'123']>",
"<NSLayoutConstraint:0x600000096760 H:[UIButton:0x7fe4f1d1d1d0'123']-(2)-[UIButton:0x7fe4f1d1d6f0'Space']>",
"<NSLayoutConstraint:0x6000000967b0 H:[UIButton:0x7fe4f1d1d6f0'Space']-(2)-[UIButton:0x7fe4f1d1d8d0'Return']>",
"<NSLayoutConstraint:0x600000096800 H:[UIButton:0x7fe4f1d1d8d0'Return']-(2)-| (Names: '|':UIInputView:0x7fe4f1f04d00)>",
"<NSLayoutConstraint:0x600000096e40 'UIView-Encapsulated-Layout-Width' H:[UIInputView:0x7fe4f1f04d00(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000000967b0 H:[UIButton:0x7fe4f1d1d6f0'Space']-(2)-[UIButton:0x7fe4f1d1d8d0'Return']>
所有4個按鈕.translatesAutoresizingMaskIntoConstraints = NO;
我想知道什麼是錯的?幫助是非常感謝:)
FYI:我在iOS8上的SDK
似乎是一個完全合乎邏輯的約束條件。在過去的幾天裏,我一直在抨擊我的頭腦。順便說一句,@Chamira Fernando在按鈕上還有其他寬度限制嗎?內部內容大小等?您是否嘗試將compressionResistancePriority或contentHuggingPriority設置爲高或低值?只要看看會發生什麼? – 2014-09-18 11:35:50
約束失敗的原因顯然是由'UIView-Encapsulated-Layout-Width'的寬度爲0.'UIInputView'位於何處? – 2014-09-18 12:17:24
傻我 - 我沒有看到(0)。我遇到過同樣的問題。它是由UIInputViewController提供的UIInputView - 鍵盤擴展的根視圖(iOS8)。我不知道爲什麼它會希望寬度爲0,考慮到默認行爲(根據文檔)應該堅持屏幕寬度。 – 2014-09-18 22:05:42