xcode 图像视图的位置不明确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32075002/
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
Position is ambiguous for image view
提问by BJM
回答by Andrew Feng
From the snapshot you provided, you were not using Stack View, so you probably were following the older tutorial.
从您提供的快照来看,您没有使用Stack View,因此您可能正在学习较旧的教程。
I also had this problem when I was following apple's tutorial, and it turned out that I placed the image view out of my Stack View, which gives me the error you mentioned; and more importantly, when I tested the app and chose an image, the image was displayed at its original size.
我在学习苹果的教程时也遇到了这个问题,结果我把图像视图放在了我的Stack View 之外,这给了我你提到的错误;更重要的是,当我测试应用程序并选择图像时,图像以原始大小显示。
So the solution for me is simple: placing image view into the Stack View, as shown below:
所以我的解决方案很简单:将图像视图放入Stack View,如下所示:
回答by Peter
You need to set all the constraint for the ui elements. Aspect ratio isn't enough, you should set the x and y position too for that image. (e.g.: leading space to View and top space to Button)
您需要为 ui 元素设置所有约束。纵横比不够,您还应该为该图像设置 x 和 y 位置。(例如:前导空间到视图和顶部空间到按钮)
If you want to use auto layout, you should allways set all the constraints for all the elements.
如果要使用自动布局,则应始终为所有元素设置所有约束。
EDIT - for better understanding
编辑 - 为了更好地理解
Just setting the aspect ratio for a view isn't enough. You should give other position and size data too.
In this example, the Leading Space to: Superview
set the X coordinate. The Top Space to Top Layout Guide
set the Y coordinate. After that we set aspect ratio, and width, or height data for the view. Like the image below.
仅设置视图的纵横比是不够的。您也应该提供其他位置和尺寸数据。在本例中,Leading Space to: Superview
设置 X 坐标。该Top Space to Top Layout Guide
组Y坐标。之后,我们为视图设置纵横比、宽度或高度数据。就像下图一样。
For better understanding I recommended you to check Stanford iOS developer lessons in iTunesU. Thats will help you understand auto layout.
为了更好地理解,我建议您查看 iTunesU 中的斯坦福 iOS 开发人员课程。这将帮助您了解自动布局。