美文网首页
iOS 13适配

iOS 13适配

作者: iOS程序猿猿猿猿 | 来源:发表于2019-10-30 20:21 被阅读0次

    获取 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
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 13适配

          本文链接:https://www.haomeiwen.com/subject/dbyavctx.html