xcode 错位视图警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23345678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Misplaced view warning
提问by Konstantin Cherkasov
My view position:
我的观点:
My constraints:
我的限制:
Last two constraints is equal to 0.
最后两个约束等于 0。
Warning:
警告:
"Vertical position will be 428 at run time but is 420 in the canvas."
“运行时垂直位置为 428,但在画布中为 420。”
Seems like a fake warning, because when I launch it, my button is on right place. How can i fix warning or hide it?
似乎是假警告,因为当我启动它时,我的按钮在正确的位置。如何修复警告或隐藏它?
回答by Douglas
If you remove all the constraints and then put them back in. It should work. This happens sometimes when you place your constraints, then move the view by dragging on it by mistake. It has happened to me before. Click on your view and down at the bottom of the storyboard you have a couple of boxes. One of them was for placing your constraints, the one next (to the right) to that has an option to remove all constrain on the view. As long as the view is selected you will remove them all on just the view. Then put them back in the way you want and the warning will go away. You may have just nudged the view a bit without knowing. Let us know if this works.
如果您删除所有约束,然后将它们放回原处。它应该可以工作。当您放置约束,然后错误地拖动视图移动视图时,有时会发生这种情况。我以前也遇到过这种情况。单击您的视图,然后在故事板底部向下您有几个框。其中之一用于放置您的约束,旁边(右侧)的一个可以选择删除视图上的所有约束。只要选择了视图,您就会在视图上将它们全部删除。然后将它们放回您想要的方式,警告就会消失。您可能只是在不知道的情况下稍微轻推了视图。让我们知道这是否有效。
EDIT #1
编辑#1
That is pretty strange. I have followed my directions in a sample project and things worked out fine. No warnings. However, I noticed that your lower constraint you said was 0. Look at my picture it is actually 88.
这很奇怪。我在一个示例项目中遵循了我的指示,并且一切顺利。没有警告。但是,我注意到你说的下限是0。看我的图片,它实际上是88。
I think you need to choose bottom layout guide when you select the lower constraint. I don't know why yours would come out as zero. Give it a go and let us know.
我认为您在选择下约束时需要选择底部布局指南。我不知道为什么你的结果为零。试一试,让我们知道。
回答by Zev Eisenberg
If you click on the warning, it will give you the option to reposition the view to match the constraints, and another to adjust the constraints to match the view's current position. You shouldn't have to delete and re-add the constraints unless you are doing something really complicated.
如果单击警告,它将为您提供重新定位视图以匹配约束的选项,以及另一个调整约束以匹配视图当前位置的选项。除非您正在做一些非常复杂的事情,否则您不必删除和重新添加约束。
As Douglas said, this state occurs if you have moved the view or set the constraints to values that do not match the current position of the view. The Interface Builder UI will typically not move views without your permission, but when you run the app, the constraints are evaluated without reference to how your views are positioned in the xib/storyboard.
正如Douglas 所说,如果您移动了视图或将约束设置为与视图当前位置不匹配的值,则会出现这种状态。未经您的许可,Interface Builder UI 通常不会移动视图,但是当您运行应用程序时,会在不参考您的视图在 xib/storyboard 中的位置的情况下评估约束。
回答by wannaBeGeek
To resolve this issue you have to select your interface builder then go to editor panel->Resolve Auto Layout Issue->Update Frame and you will be done.It worked for me.Enjoy!
要解决此问题,您必须选择您的界面构建器,然后转到编辑器面板-> 解决自动布局问题-> 更新框架,您将完成。它对我有用。享受!