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

查看:12
本文介绍了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天全站免登陆