iOS:检测设备是否为iPhone X系列(无框) [英] iOS: Detect if the device is iPhone X family (frameless)

查看:99
本文介绍了iOS:检测设备是否为iPhone X系列(无框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,有一些适用于无框设备(iPhoneX,Xs Xs max,Xr)的逻辑.当前,它基于设备的模型工作,因此,我通过DeviceKit框架检测了该模型.

In my app there is some logic for frameless devices (iPhoneX, Xs Xs max, Xr). Currently it works base on the model of the devices, so, I detect the model by DeviceKit framework.

但是我想将此逻辑扩展到将来的无框设备.大概一年后,我们将有一些额外的无框设备.因此,如何检测设备是否无框架?它应该涵盖所有当前的无框设备以及将来的无框设备.

But I want to extend this logic to future frameless devices. Probably in one year we will have some extra frameless devices. So, how can I detect if device is frameless or not? It should cover all current frameless devices and future one.

我们不能依靠faceID,safeAreaInset,屏幕高度或大小.那又如何呢?

We can not rely on faceID, safeAreaInset, screen height or size. So, then what?

推荐答案

您可以拟合"最佳状态,例如:

You could "fitler" for the top notch, something like:

var hasTopNotch: Bool {
    if #available(iOS 11.0, tvOS 11.0, *) {
        return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
    }
    return false
}

这篇关于iOS:检测设备是否为iPhone X系列(无框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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