ios 框架“在运行时会有所不同”......这不是重点吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32740721/
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
Frame "will be different at run time".... Isn't that the whole point?
提问by Electro-Bunny
Maybe striving for a "warning free" project is futile, but I am nervous enough about Adaptive Layout/ AutoLayout that I am compelled to try and squash these warnings.
也许争取一个“无警告”项目是徒劳的,但我对自适应布局/自动布局非常紧张,我不得不尝试压制这些警告。
I have a uiview that I want to be dynamically sized based on the portrait screen width. I have my app set in the Build Info for Universal, Portrait only (and upside down). I have constrained the uiview the following ways:
我有一个 uiview,我想根据纵向屏幕宽度动态调整大小。我在通用的构建信息中设置了我的应用程序,仅限纵向(颠倒)。我通过以下方式限制了 uiview:
- Aligned the view's Center to Superview's center X
- Made the view's width proportional to the Superview's width
- Gave the view an aspect ratio constraint of 1:1
- Given the view a vertical constraint to the superview's top
- 将视图的中心与超级视图的中心 X 对齐
- 使视图的宽度与超级视图的宽度成正比
- 给视图一个 1:1 的纵横比约束
- 鉴于视图对超级视图顶部的垂直约束
For details please see the screenshot below.
有关详细信息,请参阅下面的屏幕截图。
So now I get the warnings about the view's "frame being different at run time", in particular the size and position at runtime versus what is in the canvas. Not sure why Xcode "cares" about the canvas where the class sizes are set to Any height and Any width. I thought the whole point of Adaptive layout is that sizes and positions are resolved at runtime based on the devices screen size and orientation.
所以现在我收到了关于视图“运行时框架不同”的警告,特别是运行时的大小和位置与画布中的内容。不知道为什么 Xcode 会“关心”类大小设置为任意高度和任意宽度的画布。我认为自适应布局的重点是在运行时根据设备屏幕大小和方向解析大小和位置。
If I breakdown and let Xcode "Update frames"... yes the warning goes away, but with the super large views it is virtually impossible to work graphically in the tiny canvas in a WYSIWIG fashion. Any solution here to getting rid of the warnings without creating oversized views that make working inside the canvas nearly impossible?
如果我崩溃并让 Xcode“更新帧”......是的,警告就会消失,但是对于超大视图,几乎不可能以所见即所得的方式在小画布中以图形方式工作。这里有什么解决方案可以消除警告而不创建使在画布内工作几乎不可能的超大视图?
采纳答案by Ale? Oskar Kocur
回答by ullstrm
To get rid of the warning, and let the constraints place the views "correctly", just select the view that is giving the warning, press the little triangle thing in the bottom right corner of the storyboard:
要摆脱警告,并让约束“正确”放置视图,只需选择发出警告的视图,按故事板右下角的小三角形:
And then select "Update frames" for "All Views in Container"
然后为“容器中的所有视图”选择“更新框架”
(I wish there was some way of doing this to a whole storyboard. At least I haven't found it)
(我希望有某种方法可以对整个故事板执行此操作。至少我还没有找到)
回答by Suragch
Select a view and press
选择一个视图并按下
- Option+ Command+ =
- Option+ Command+=
This will update the frame size. Repeat for all offending views. It doesn't take that long, especially if you find them by clicking on the error messages.
这将更新帧大小。对所有违规视图重复此操作。不需要那么长时间,尤其是当您通过单击错误消息找到它们时。
Thanks to this answerfor the idea.
Notes
笔记
After updating to Xcode 8, and choosing some View as device, I was getting this error. The menu is different than in Xcode 7, so @Spoek's answer was no longer working. Also clicking Update or Reset was not working for me.
更新到 Xcode 8 并选择一些 View 作为设备后,我收到此错误。该菜单与 Xcode 7 中的不同,因此 @Spoek 的回答不再有效。同样单击更新或重置对我不起作用。
Update
更新
Update Frames now has its own button. That's why I missed it before.
更新框架现在有自己的按钮。这就是为什么我之前错过了它。