iOS 13适配

2019-10-30  本文已影响0人  iOS程序猿猿猿猿

获取 keywindow

private func keywindows() -> UIWindow? {
    var window:UIWindow? = nil
    if #available(iOS 13.0, *) {
        for windowScene:UIWindowScene in ((UIApplication.shared.connectedScenes as?  Set<UIWindowScene>)!) {
            if windowScene.activationState == .foregroundInactive || windowScene.activationState == .foregroundActive {
                window = windowScene.windows.first
                break
            }
        }
        return window
    }else{
        return  UIApplication.shared.keyWindow
    }
}

获取状态栏高度

private func stateHeight() -> CGFloat {
    if #available(iOS 13.0, *) {
        return (keywindows().windowScene?.statusBarManager!.statusBarFrame.height)!
    }else {
        return UIApplication.shared.statusBarFrame.height
    }
}
上一篇下一篇

猜你喜欢

热点阅读