如何将图像约束到iPhone X上的View Controller底部(在主页指示器下面)

时间:2023-01-22 17:00:23

I have a view controller that looks fine on all devices but leaves an undesired white padding behind the Home Indicator on iPhone X. I would like my background image to extend all the way to the bottom margin, and be behind the home indicator like, for example, a tab bar does.

我有一个视图控制器在所有设备上看起来都很好,但在iPhone X上的Home Indicator后面留下了一个不需要的白色填充。我希望我的背景图像一直延伸到底部边缘,并且在主页指示器后面,如标签栏就是这样的。

如何将图像约束到iPhone X上的View Controller底部(在主页指示器下面)

I realize that I could use negative margin over the image, but then that means that I am cutting part of it on other devices. I also setting a parameter to "prefer hiding the home indicator" but it simply hides the bar, and does not extend the image to the margin.

我意识到我可以在图像上使用负边距,但这意味着我正在其他设备上切割它的一部分。我还将参数设置为“更喜欢隐藏主页指示符”,但它只是隐藏了条形图,并且没有将图像扩展到边距。

Is there a better way to achieve this?

有没有更好的方法来实现这一目标?

1 个解决方案

#1


2  

Finally got to a solution!

终于得到了解决方案!

First of all, you need to either use a "new" View Controller that contains the Safe Area Layout Guides, or activate them on the Document tab of the View Controller:

首先,您需要使用包含“安全区域布局指南”的“新”视图控制器,或者在视图控制器的“文档”选项卡上激活它们:

如何将图像约束到iPhone X上的View Controller底部(在主页指示器下面)

After this, you need to realize that a safe area is the view from above the Home Indicator up to below the Status Bar. However, once Safe Area Layout Guides are activated, if you set a constraint to the bottom of the superview, it will go beyond the Safe Area and into the actual bottom (or top if so desired) of the View Controller.

在此之后,您需要意识到安全区域是从主页指示器上方到状态栏下方的视图。但是,一旦激活了“安全区域布局指南”,如果将约束设置到超级视图的底部,它将超出安全区域并进入视图控制器的实际底部(或顶部,如果需要)。

Hope this helps!

希望这可以帮助!

#1


2  

Finally got to a solution!

终于得到了解决方案!

First of all, you need to either use a "new" View Controller that contains the Safe Area Layout Guides, or activate them on the Document tab of the View Controller:

首先,您需要使用包含“安全区域布局指南”的“新”视图控制器,或者在视图控制器的“文档”选项卡上激活它们:

如何将图像约束到iPhone X上的View Controller底部(在主页指示器下面)

After this, you need to realize that a safe area is the view from above the Home Indicator up to below the Status Bar. However, once Safe Area Layout Guides are activated, if you set a constraint to the bottom of the superview, it will go beyond the Safe Area and into the actual bottom (or top if so desired) of the View Controller.

在此之后,您需要意识到安全区域是从主页指示器上方到状态栏下方的视图。但是,一旦激活了“安全区域布局指南”,如果将约束设置到超级视图的底部,它将超出安全区域并进入视图控制器的实际底部(或顶部,如果需要)。

Hope this helps!

希望这可以帮助!