///1. 获得当前窗口 var JY_WINDOW: UIWindow? { get{ if let app = UIApplication.shared.delegate as? AppDelegate { return app.window } return nil } } //2. iPhoneX系列 var iphoneX_Series: Bool { get { if UIDevice.current.userInterfaceIdiom != UIUserInterfaceIdiom.phone{ debugPrint("不是iPhone, 是 \(UIDevice.current.userInterfaceIdiom.rawValue)") } if #available(iOS 11.0, *) { if let bottom = JY_WINDOW?.safeAreaInsets.bottom , bottom > 0 { return true } } else { debugPrint("iOS11 之前的版本") } return false } }
安全区高度: if #available(iOS 11.0, *) { let top = JY_WINDOW?.safeAreaInsets.top let bottom = JY_WINDOW?.safeAreaInsets.bottom let height = UIScreen.main.bounds.size.height - top - bottom } else { let height = UIScreen.main.bounds.size.height }