ios16 旋转屏幕

2024-01-03  本文已影响0人  九月_adhoc
      AppDelegateProvider.shared.delegate?.setLandscapeRight(true)
        
        if #unavailable(iOS 16) {
                 let value = UIInterfaceOrientation.landscapeRight.rawValue
                 if UIDevice.current.responds(to: #selector(setValue(_:forKey:))) {
                     // 及时更新旋转的方向,如果不更新,可能造成旋转失败
                     _ = AppDelegateProvider.shared.delegate?.applicationInApp(UIApplication.shared, supportedInterfaceOrientationsFor: UIApplication.shared.keyWindow)
                     UIDevice.current.setValue(value, forKey: "orientation")
                     UIViewController.attemptRotationToDeviceOrientation()
                 }
        }else{
//                  let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
//                _ = AppDelegateProvider.shared.delegate?.applicationInApp(UIApplication.shared, supportedInterfaceOrientationsFor: UIApplication.shared.keyWindow)
//                   UIApplication.shared.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations()
////                      navController.setNeedsUpdateOfSupportedInterfaceOrientations()
//                       windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeRight)) { error in
//                           print(error)
//                           print(windowScene?.effectiveGeometry ?? "")
//                       }
        }
        
        UIApplication.shared.keyWindow?.rootViewController!.present(navController, animated: animated, completion: nil)
        
//        if #available(iOS 16, *) {
//            let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
//            _ = AppDelegateProvider.shared.delegate?.applicationInApp(UIApplication.shared, supportedInterfaceOrientationsFor: UIApplication.shared.keyWindow)
//            UIApplication.shared.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations()
//            navController.setNeedsUpdateOfSupportedInterfaceOrientations()
//            windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeRight)) { error in
//                print(error)
//                print(windowScene?.effectiveGeometry ?? "")
//            }
//        }

上一篇 下一篇

猜你喜欢

热点阅读