ios16 旋转屏幕

      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 ?? "")
//            }
//        }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容