diff --git a/WOKA/Games/Controller/GamesWebViewVC.swift b/WOKA/Games/Controller/GamesWebViewVC.swift index 59e0731..3cf0d80 100644 --- a/WOKA/Games/Controller/GamesWebViewVC.swift +++ b/WOKA/Games/Controller/GamesWebViewVC.swift @@ -19,6 +19,9 @@ class GamesWebViewVC: UIViewController { super.viewDidLoad() if let orientation, orientation == .landscape{ + appDelegate.deviceOrientation = .landscapeRight + let value = UIInterfaceOrientation.landscapeRight.rawValue + UIDevice.current.setValue(value, forKey: "orientation") rotateToLandsScapeDevice() } @@ -32,29 +35,29 @@ class GamesWebViewVC: UIViewController { } func rotateToLandsScapeDevice(){ - let appDelegate = UIApplication.shared.delegate as! AppDelegate - appDelegate.myOrientation = .landscapeRight - if #available(iOS 16.0, *) { - let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: UIInterfaceOrientationMask.landscapeRight)) - } else { - UIDevice.current.setValue(UIInterfaceOrientationMask.landscapeRight.rawValue, forKey: "orientation") - } - UIView.setAnimationsEnabled(true) +// let appDelegate = UIApplication.shared.delegate as! AppDelegate +// appDelegate.myOrientation = .landscapeRight +// if #available(iOS 16.0, *) { +// let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene +// windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: UIInterfaceOrientationMask.landscapeRight)) +// } else { +// UIDevice.current.setValue(UIInterfaceOrientationMask.landscapeRight.rawValue, forKey: "orientation") +// } +// UIView.setAnimationsEnabled(true) } func rotateToPotraitScapeDevice(){ - let appDelegate = UIApplication.shared.delegate as! AppDelegate - appDelegate.myOrientation = .portrait - if #available(iOS 16.0, *) { - let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: UIInterfaceOrientationMask.portrait)) - } else { - UIDevice.current.setValue(UIInterfaceOrientationMask.landscapeRight.rawValue, forKey: "orientation") - } -// UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") - UIView.setAnimationsEnabled(true) +// let appDelegate = UIApplication.shared.delegate as! AppDelegate +// appDelegate.myOrientation = .portrait +// if #available(iOS 16.0, *) { +// let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene +// windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: UIInterfaceOrientationMask.portrait)) +// } else { +// UIDevice.current.setValue(UIInterfaceOrientationMask.landscapeRight.rawValue, forKey: "orientation") +// } +//// UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") +// UIView.setAnimationsEnabled(true) } @IBAction func backBtnTapped(_ sender: UIButton) { @@ -67,10 +70,14 @@ class GamesWebViewVC: UIViewController { vcPush.onDoneBlock = { mode in switch mode{ case .yes: - self.rotateToPotraitScapeDevice() - Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in - self.dismiss(animated: true) - } + appDelegate.deviceOrientation = .portrait + + let value = UIInterfaceOrientation.portrait.rawValue + UIDevice.current.setValue(value, forKey: "orientation") + UIViewController.attemptRotationToDeviceOrientation() +// Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in +// self.dismiss(animated: true) +// } case .no: print("no") } @@ -80,4 +87,25 @@ class GamesWebViewVC: UIViewController { self.present(vcPush, animated: true) } + // MARK: - Handle Screen Transition + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + coordinator.animate(alongsideTransition: nil) { _ in + self.checkOrientation() + } + } + + private func checkOrientation() { + let isPortrait = UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height + if isPortrait { + print("Device is in portrait mode") + Timer.scheduledTimer(withTimeInterval: 0.4, repeats: false) { _ in + self.dismiss(animated: true) + } + } else { + print("Device is in landscape mode") + } + } } diff --git a/WOKA/Main/Delegate/AppDelegate.swift b/WOKA/Main/Delegate/AppDelegate.swift index 385cc63..84e23bb 100644 --- a/WOKA/Main/Delegate/AppDelegate.swift +++ b/WOKA/Main/Delegate/AppDelegate.swift @@ -11,15 +11,24 @@ import IQKeyboardManagerSwift import JWPlayerKit import Firebase +let appDelegate = UIApplication.shared.delegate as! AppDelegate + @main class AppDelegate: UIResponder, UIApplicationDelegate { +// var window: UIWindow? +// +// var myOrientation: UIInterfaceOrientationMask = .portrait +// +// func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { +// return myOrientation +// } + var window: UIWindow? - - var myOrientation: UIInterfaceOrientationMask = .portrait + var deviceOrientation = UIInterfaceOrientationMask.portrait func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { - return myOrientation + return deviceOrientation } private func registerCustomFonts() { diff --git a/WOKA/Theme/Base.lproj/Theme.storyboard b/WOKA/Theme/Base.lproj/Theme.storyboard index 56f95bb..e03ad2e 100644 --- a/WOKA/Theme/Base.lproj/Theme.storyboard +++ b/WOKA/Theme/Base.lproj/Theme.storyboard @@ -995,7 +995,7 @@