刚刚开始学习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