所有 iPad(包括 iPad pro)的常规/常规仓位大小限制? [英] Regular / Regular position sizing constraints for all iPads, including iPad pro?

查看:12
本文介绍了所有 iPad(包括 iPad pro)的常规/常规仓位大小限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在约束中使用了乘数来调整视图的大小.然而,在我对位置的约束中,我使用了值,我会针对不同的尺寸等级进行更改.

I've used multipliers in my constraints, to size my views. However in my constraints for position I've used values, which I change for different sizing classes.

但是对于 iPad Pro 使用常规/常规尺寸类,它的位置值不够大,但对于其他 iPad 来说没问题.

However using regular / regular sizing classes for iPad Pro it's positions values aren't big enough, but for other iPads it's fine.

我真的不必添加带有乘数的定位视图来为我的所有视图提供百分比空间吗?

I seriously don't have to add positioning views with multipliers to provide percentage spaces for all my views as well do I?

推荐答案

我们要做的是根据屏幕大小设置屏幕顶部和子视图顶部之间的边距.这意味着约束必须与父视图的高度相关.

What we're after is to set the margin between the top of the screen and the top of the subview with relation to the size of the screen. This means the constraint must be related to the superview's height.

试图设置两个视图之间的距离(在传统意义上)在这种情况下实际上是一个的想法.相反,试试这个.

Trying to set the distance between the two views (In the traditional sense) is actually a bad idea in this case. Instead, try this.

添加一个约束以使您的视图在超级视图中垂直居中.现在,在尺寸检查器(右侧工具栏)中打开约束.

Add a constraint to center your view vertically in the superview. Now, open up the constraint in the size inspector (The right toolbar).

如果您将乘数设置为 0.01(0 只是将其放回屏幕中心),您的视图将超出屏幕顶部.将 第一项 从 Center Y 更改为 Top.现在您的视图将位于顶部!

If you set the multiplier to 0.01 (0 just puts it back in the center of the screen), your view will go past the top of the screen. Change the first item from Center Y to Top. Now your view will be at the top!

从这里,您可以更改 constant 以将您的视图向下移动一个固定的量,并更改 multiplier 以将您的视图进一步向下移动按比例 到屏幕的高度.公式看起来像

From here, you can change the constant to move your view down a fixed amount and change the multiplier to move your view down further proportionally to the screen's height. The formula would look like

subViewYPosition = constant + (superviewHeight * multiplier)

您需要调整常数和乘数以满足您的需要,但我相信这是解决问题的好方法.一个例子如下所示.

You will need to adjust the constant and multiplier to suit your needs, but I believe this is a good solution to the problem. An example of this is shown below.

这篇关于所有 iPad(包括 iPad pro)的常规/常规仓位大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆