[英]Auto Layout of view hides subviews
I have a UIViewController embedded in a Navigation Controller. 我在导航控制器中嵌入了UIViewController。 I am using autolayout.
我正在使用自动版式。 In interface builder this is how the VC looks.
在界面生成器中,这就是VC的外观。
But when run in the simulator I get this: 但是当在模拟器中运行时,我得到以下信息:
With this error. 出现这个错误。
2016-08-10 16:51:17.077 My App[11797:7752671] Unable to simultaneously satisfy constraints.
2016-08-10 16:51:17.077我的应用程序[11797:7752671]无法同时满足约束。 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;
尝试以下操作:(1)查看每个约束,并尝试找出不期望的约束; (2) find the code that added the unwanted constraint or constraints and fix it.
(2)查找添加了一个或多个不必要约束的代码并进行修复。 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<_UILayoutSupportConstraint:0x7fad72f7d6b0 V:[_UILayoutGuide:0x7fad72e5d1d0(64)]>", "<_UILayoutSupportConstraint:0x7fad72ffa6a0 V:|-(0)-[_UILayoutGuide:0x7fad72e5d1d0] (Names: '|':UIView:0x7fad72fe1b40 )>", "<_UILayoutSupportConstraint:0x7fad72fe2460 V:[_UILayoutGuide:0x7fad72e64760(0)]>", "<_UILayoutSupportConstraint:0x7fad72fe1470 _UILayoutGuide:0x7fad72e64760.bottom == UIView:0x7fad72fe1b40.bottom>", "", "", "", "")
(注意:如果看到的是您不了解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性的文档translationsAutoresizingMaskIntoConstraints)(“ <_UILayoutSupportConstraint:0x7fad72f7d6b0 V:[_ UILayoutGuide:0x7fad72e5d1d0(stra)<64]> V:|-(0)-[_ UILayoutGuide:0x7fad72e5d1d0](名称:'|':UIView:0x7fad72fe1b40)>“,” <_UILayoutSupportConstraint:0x7fad72fe2460 V:[_ UILayoutGuide:0x7fad72e47060(0)]>“,” <__ _UILayoutGuide:0x7fad72e64760.bottom == UIView:0x7fad72fe1b40.bottom>“,”“,”“,”“,”“)
Will attempt to recover by breaking constraint
将尝试通过打破约束来恢复
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
在UIViewAlertForUnsatisfiableConstraints上创建一个符号断点,以在调试器中捕获该断点。 The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
列出的UIView的UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
I have rebuilt this view several times. 我已经多次重建了这种观点。 I go up to Editor > Resolve Auto Layout Issues > "All Views" Reset to Suggested Constrains .
我转到“ 编辑器” >“ 解决自动布局问题” > “所有视图”重置为“建议约束” 。
Which generates this: 哪个生成此:
I have even manually deleted all constrains and started over. 我什至手动删除了所有约束并重新开始。
But nothing works. 但是什么都行不通。
I have nothing in the .m file that lays anything out or adjust sizes or locations. .m文件中没有任何内容可以布局或调整大小或位置。 Nothing fancy is happening with this view.
这种观点毫无幻想。 What am I doing wrong?
我究竟做错了什么?
Editor > Resolve Auto Layout Issues > "All Views" Reset to Suggested Constrains almost never works correctly. 编辑器>解决自动布局问题>“所有视图”重置为建议的约束几乎永远无法正常工作。 So just avoid it.
所以就避免吧。
When adding constraints, you need to specify four things for every item: 添加约束时,需要为每个项目指定四件事:
There are creative ways to do this, so for you I would suggest you add these constraints to the Lookup Button: 有一些创造性的方法可以做到这一点,因此建议您向“查找”按钮添加以下约束:
Your x location and width are satisfied by Horizontally in Center and Leading or Trailing Space. 您的x位置和宽度由“居中水平”和“前导或尾随空间”满足。 These two constraints center the button and give you equal space on either side of the button.
这两个约束使按钮居中,并在按钮的两侧留出相等的空间。 The button will be as wide as the view minus the space on both sides.
该按钮的宽度将等于视图减去两侧的空间。 Setting the height obviously satisfies the height of the button and Top Space satisfies the y position of your button.
设置高度显然可以满足按钮的高度,并且“顶部空间”可以满足按钮的y位置。 Therefore you have easily satisfied x location, y location, width and height of the button, and you are done.
因此,您很容易满足按钮的x位置,y位置,宽度和高度,就可以完成。
You need to start over and think about constraints you are making. 您需要重新开始,并考虑您正在制定的约束。 Think about what information is known, what sizes should not change.
考虑一下已知的信息,什么大小不应更改。 Tell this information to Auto Layout.
将此信息告知自动版式。
Your button is not appearing because Auto Layout does not known how to position it, it missing following numbers. 您的按钮未出现,因为“自动版面配置”不知道如何放置,因为缺少以下数字。 Delete all constraints and start over with the following.
删除所有约束并重新开始以下操作。 Not you can change this numbers.
不是,您可以更改此数字。
20.0
20.0
0
with margin 0
有边距 0
with margin 0
有边距 0
with margin 0
有保证金 0
with margin 0
有边距 20.0
20.0
Reset to suggested constraints never solves your problem, it only hides the warning. 重置为建议的约束永远不会解决您的问题,只会隐藏警告。 You have to set the constraints that suits for your requirement.
您必须设置适合您要求的约束。 From your question, when you choose the option, Reset to suggested constraints, the autolayout will give a bottom layout constraint for the LOOK UP button,and it had too much of bottom constraint(which happens when you rest to suggested constraint), hence it is pushed up in the runtime.
根据您的问题,当您选择“重置为建议的约束”选项时,自动布局将为“向上查看”按钮提供底部布局约束,并且其底部约束过多(当您休息到建议的约束时会发生这种情况),因此在运行时被上推。
You just need top and leading/ top and center horizontal constraint for your button corresponding to its above textfield along with height and width constraint. 您只需要按钮的顶部和顶部/顶部和中央水平约束(对应于其上方的文本字段)以及高度和宽度约束即可。 Remove the bototm constraint for your LOOK up button.
删除您的LOOK向上按钮的bototm约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.