【发布时间】:2015-08-07 17:30:33
【问题描述】:
我正在尝试将一个按钮固定在所有 4 个侧面,以将按钮对象固定在我任意放置的确切位置,但是当我运行它时出现以下错误。任何见解或帮助将不胜感激。
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)
(
"<_UILayoutSupportConstraint:0x9f494b0 V:[_UILayoutGuide:0x9f40370(20)]>",
"<_UILayoutSupportConstraint:0x9f3b6c0 V:|-(0)-[_UILayoutGuide:0x9f40370] (Names: '|':UIView:0x9f3feb0 )>",
"<_UILayoutSupportConstraint:0x9f418e0 V:[_UILayoutGuide:0x9f407c0(0)]>",
"<_UILayoutSupportConstraint:0x9f18010 _UILayoutGuide:0x9f407c0.bottom == UIView:0x9f3feb0.bottom>",
"<NSLayoutConstraint:0x9f40f10 V:[UIButton:0x9f40f40'Button']-(211)-[_UILayoutGuide:0x9f407c0]>",
"<NSLayoutConstraint:0x9f47ab0 V:[_UILayoutGuide:0x9f40370]-(539)-[UIButton:0x9f40f40'Button']>",
"<NSLayoutConstraint:0xa157b10 'UIView-Encapsulated-Layout-Height' V:[UIView:0x9f3feb0(568)]>"
)
Will attempt to recover by breaking constraint
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.
【问题讨论】:
-
您的约束相互冲突。您可能想要发布您的 Interface Builder 视图的屏幕截图,因为更容易直观地确定您在哪里遇到了可能发生冲突的约束。 Interface Builder 有时可以作为 PITA 来处理,但一旦你“掌握了窍门”,它就会大大节省时间。
-
@AdrianB 对不起。刚刚上传了截图。所以我将一个按钮移动到视图中,并希望它位于那个确切的位置。如前所述,我固定了所有 4 个面,但得到了错误。将对象放置在您想要的确切位置的最佳方法是什么?谢谢!
-
如果视图的大小发生变化,您预计会发生什么?
-
@AminNegm-Awad 抱歉,但不能安静地得到您的要求。能详细点吗?
-
@KoKi 我更新了我的答案。您遇到的错误并不是什么大问题——它只是告诉您存在冲突,Xcode 为您解决了它。对于您所拥有的,您只需将其固定在两侧,而不是 4 侧。或者,您可以尝试调整按钮的尺寸。
标签: ios objective-c debugging ios-autolayout