Created
June 24, 2021 02:10
-
-
Save T-Pham/0ed5a6ab2fdc9293e4071367dd64b658 to your computer and use it in GitHub Desktop.
Get UIInterfaceOrientation based on UIScreen's UICoordinateSpaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIScreen { | |
var orientation: UIInterfaceOrientation { | |
let convertedZeroPoint = fixedCoordinateSpace.convert(CGPoint.zero, to: coordinateSpace) | |
let coordinateSpaceBounds = coordinateSpace.bounds | |
switch convertedZeroPoint { | |
case .zero: | |
return .portrait | |
case CGPoint(x: coordinateSpaceBounds.maxX, y: coordinateSpaceBounds.minY): | |
return .landscapeLeft | |
case CGPoint(x: coordinateSpaceBounds.minX, y: coordinateSpaceBounds.maxY): | |
return .landscapeRight | |
case CGPoint(x: coordinateSpaceBounds.maxX, y: coordinateSpaceBounds.maxY): | |
return .portraitUpsideDown | |
default: | |
return .unknown | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment