how do i get screen Orientation in Ios I couldn't figure it out
Copy code
actual fun Scope.isScreenLandscape(): Boolean {
return true
}
j
Jan Holešovský
02/16/2024, 12:38 PM
Get the first window in
UIApplication
, and get its
windowScene
which has the
interfaceOrientation
y
youssef
02/16/2024, 1:24 PM
got the first window like so :
Copy code
val mainWindow = UIApplication.sharedApplication.windows.firstOrNull()
and there is no such thing as windowScene
j
Jan Holešovský
02/16/2024, 2:40 PM
I have this in my project, hope this helps:
val window = UIApplication.sharedApplication.windows.first() as? UIWindow
return when (window?.windowScene?.interfaceOrientation) {
UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight -> { /* landscape */ }
else -> { /* portrait */ }
}