///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
        }

  

posted on 2018-10-17 10:24  懂事长qingzZ  阅读(2173)  评论(0编辑  收藏  举报