如何正确设置此布局的约束条件?
问题描述:
我已经尝试了很长时间,但由于约束问题不断得到崩溃...如何正确设置此布局的约束条件?
如何设置此布局,使其适用于iPhone 3Gs,4和5以及iPad?
_______TOP OF SCREEN________
Table View should attach to top of screen and with 5 pixels to the Label below
flexible in height so it works on iPhone 5 and 6
____________________________
Label with fixed distance to table View above and button below
____________________________
Button with fixed distance to Label above and fixed distance to bottom of screen
____________________________
Bottom of screen
所以基本上所有的距离和高度是固定的,除了桌子的高度,应填写无论是屏幕的上方和标签
之间可每当我设置这样的contstraints我不断收到崩溃在iPhone 3的iOS 6.1:
2013-03-16 23:12:51.013 BMWhat Test[64196:907] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x1d1f2d70 h=-&- v=-&- UIView:0x1d1aac20.height == UITransitionView:0x1d174220.height - 20>",
"<NSLayoutConstraint:0x1d1c03b0 V:[UILabel:0x1c58f100(21)]>",
"<NSLayoutConstraint:0x1d1ce780 V:[UITableView:0x1cbd9000(469)]>",
"<NSLayoutConstraint:0x1c5aff30 V:[UIButton:0x1d1d1bb0(44)]>",
"<NSLayoutConstraint:0x1d1c0030 V:|-(0)-[UITableView:0x1cbd9000] (Names: '|':UIView:0x1d1aac20)>",
"<NSLayoutConstraint:0x1d1921d0 V:[UILabel:0x1c58f100]-(1)-[UIButton:0x1d1d1bb0]>",
"<NSAutoresizingMaskLayoutConstraint:0x1c58e4d0 h=--- v=--- V:[UIWindow:0x1d002230(480)]>",
"<NSLayoutConstraint:0x1d1cd6c0 V:[UITableView:0x1cbd9000]-(NSSpace(8))-[UILabel:0x1c58f100]>",
"<NSLayoutConstraint:0x1d1ca370 V:[UIButton:0x1d1d1bb0]-(5)-| (Names: '|':UIView:0x1d1aac20)>",
"<NSAutoresizingMaskLayoutConstraint:0x1d172a90 h=--& v=-&- UITransitionView:0x1d174220.height == UIWindow:0x1d002230.height>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1d1ce780 V:[UITableView:0x1cbd9000(469)]>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
在模拟器iPhone的Retina 4英寸iOS 6的正常工作。
答
问题是你指定一个垂直约束在tableview绑高度到469磅。既然你希望tableview的高度是灵活的,你不需要这个约束。
答
NSLayoutConstraint仅在iOS的支持6
iPhone 3不支持的iOS 6 3Gs的是做的最早的模型。
+0
感谢您指出这一点 - 我的意思是3Gs。这个问题更多的是如何自己做约束,所以它不会崩溃。无论如何,我只是意识到,在手机本身 - 没有连接到调试器 - 它并不重要,因为它不会崩溃。可能是这样的路要走吗?只要它在电话上很好,一个不关心恢复的崩溃:-) – user387184 2013-03-16 23:18:02
完美 - 感谢您的帮助!顺便说一下,有一种方法来检查这些约束问题之前运行某种方式,让他们显示我更好的方式? – user387184 2013-03-17 06:30:29
我不认为这些工具还支持这一点。约束的解决方案最终取决于运行时实际窗口的大小和方向,所以我不确定这些工具在编译时能够完全检测到问题。但是在运行时,您会看到像您看到的异常,并且您还可以在运行时检查不明确的约束。 – 2013-03-17 18:05:43
花了很多时间后,高度正是冲突的约束。万分感谢! – Tomer 2013-07-13 03:44:24