iPhone X上的额外底部空间/填充? [英] Extra bottom space/padding on iPhone X?

查看:185
本文介绍了iPhone X上的额外底部空间/填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在纵向模式下的iPhone X上,如果将安全区域的底部约束设置为0,则最终会在屏幕底部留出额外的空间。
如何以编程方式获得额外填充的高度?

On the iPhone X in portrait mode, if you set a bottom constraint to safe area to 0, you will end up with an extra space at the bottom of the screen. How do you get programmatically the height of this extra padding ?

我设法手动确定此填充的高度为34,这就是我管理的方式使用iPhone X检测实现它:

I managed to manually determine the height of this padding which is 34 and here is how I managed to implement it with iPhone X detection:

Swift 4.0和Xcode 9.0

if UIDevice().userInterfaceIdiom == .phone
{
    switch UIScreen.main.nativeBounds.height
    {
        case 2436: //iPhone X
        self.keyboardInAppOffset.constant = -34.0
        default:
        self.keyboardInAppOffset.constant = 0
    }
}

有没有更清晰的方法来检测此填充的高度?

Is there a cleaner way to detect the height of this padding ?

推荐答案

在iOS 11中,视图具有 safeAreaInsets 属性。如果你获得这些插入的底部属性,你可以在iPhone X上获得底部填充的高度:

In iOS 11, views have a safeAreaInsets property. If you get the bottom property of these insets you can get the height of the bottom padding while on iPhone X:

if #available(iOS 11.0, *) {
    let bottomPadding = view.safeAreaInsets.bottom
    // ...
}

(同样适用于带状态栏的顶部填充)

(likewise for the top padding with status bar)

这篇关于iPhone X上的额外底部空间/填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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