Claude,
Here's the code from my appDelegate.
import UIKit
var gScreenSize = CGRect()
var gScreenHeight: CGFloat = 0.0
var gScreenWidth: CGFloat = 0.0
var gOrientation: String = ""
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
return true
}
@objc func rotated()
{
let theCurrentDevice = UIDevice.current
if theCurrentDevice.orientation.isValidInterfaceOrientation
{
let deviceOrientationRaw = theCurrentDevice.orientation.rawValue
switch deviceOrientationRaw
{
case 1: // Home Button at the Bottom
gScreenSize = UIScreen.main.fixedCoordinateSpace.bounds
let firstScene = window?.windowScene
if let w = firstScene
{
// gScreenSize = w.screen.bounds
print("portrait bottom", w.screen.bounds)
}
print("Portrait AppDelegate height", gScreenSize.height)
print("Portrait AppDelegate width", gScreenSize.width)
gOrientation = "Portrait" // K.Oreientation.portrait
gScreenHeight = gScreenSize.height
gScreenWidth = gScreenSize.width
case 2: // Home Button at the Top
gScreenSize = UIScreen.main.fixedCoordinateSpace.bounds
let firstScene = window?.windowScene
if let w = firstScene
{
// gScreenSize = w.screen.bounds
print("portrait top", w.screen.bounds)
}
print("Portrait AppDelegate height", gScreenSize.height)
print("Portrait AppDelegate width", gScreenSize.width)
gOrientation = "Portrait" // K.Oreientation.portrait
gScreenHeight = gScreenSize.height
gScreenWidth = gScreenSize.width
case 3: // Home Button on the Right
gScreenSize = UIScreen.main.fixedCoordinateSpace.bounds
let firstScene = window?.windowScene
if let w = firstScene
{
// gScreenSize = w.screen.bounds
print("Landscape right", w.screen.bounds)
}
print("Landscape Home Right AppDelegate height", gScreenSize.width)
print("Landscape Home Right AppDelegate width", gScreenSize.height)
gOrientation = "Landscape" // K.Oreientation.landscape
gScreenHeight = gScreenSize.width
gScreenWidth = gScreenSize.height
case 4: // Home Button on the Left
gScreenSize = UIScreen.main.fixedCoordinateSpace.bounds
let firstScene = window?.windowScene
if let w = firstScene
{
// gScreenSize = w.screen.bounds
print("Landscape left", w.screen.bounds)
}
print("Landscape Home Left AppDelegate height", gScreenSize.width)
print("Landscape Home Left AppDelegate width", gScreenSize.height)
gOrientation = "Landscape" // K.Oreientation.landscape
gScreenHeight = gScreenSize.width
gScreenWidth = gScreenSize.height
case 5:
//deviceOrreientation = "Face Up"
break
case 6:
//deviceOrreientation = "Face Down"
break
default:
// gOrientation_2 = K.Oreientation.unknown
break
}
}
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}