简体   繁体   English

具有尺寸类别的自动版式:根据iPhone屏幕尺寸的不同间距

[英]AutoLayout with size classes: Different spacing depending on iPhone screen size

I have a UIViewController set up in an UIStoryboard in Interface Builder using size classes . 我使用尺寸类在Interface Builder的UIStoryboard中设置了UIViewController

在此处输入图片说明

This looks good on an iPhone 5 with the 4" screen, but on the 5.5" screen of the iPhone 6 Plus the elements are too cramped in the top area of the device. 在具有4英寸屏幕的iPhone 5上,这看起来不错,但是在iPhone 6 Plus的5.5英寸屏幕上,元素太狭窄了。 I want to increase the constant of the spacing constraints on iPhone 6 and 6 Plus. 我想增加iPhone 6和6 Plus上的间距约束常数。

As far as I was able to see that's not possible with size classes, as there is only one size class for all iPhone displays (no matter if 3.5" or 5.5"). 据我所知,尺寸级别是不可能的,因为所有iPhone显示器只有一个尺寸级别(无论是3.5英寸还是5.5英寸)。 What is the way to do this? 这是怎么做的? Maybe something with the constraint multiplier? 也许有约束乘数? Still haven't really figured that one out. 仍然还没有真正弄清楚这一点。

See my answer here: 在这里查看我的答案:

https://stackoverflow.com/a/20865342/341994 https://stackoverflow.com/a/20865342/341994

As I explain there, you can't make a spacing constraint value depend on the height of something. 正如我在此处解释的那样,您不能使间距约束值取决于某物的高度。 But you can make a height constraint depend on the height of something. 但是您可以根据对象的高度设置高度限制。 So try adding an invisible view whose height is proportional to the superview height, and use it as a spacer, with constraints to it. 因此,请尝试添加一个不可见的视图,该视图的高度与超级视图的高度成比例,并将其用作带有约束的间隔器。 This will push the views down proportionally to the screen height. 这会将视图按比例降低到屏幕高度。

I made a quick demo. 我做了一个快速演示。 Look at how the top of the red view is further down on the iPhone 6 than it is on the iPhone 4s: 看一下iPhone 6上红色视图的顶部比iPhone 4s上的红色视图低得多:

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM