Last active
March 24, 2017 11:19
-
-
Save eleev/d3541c4a4afb0b4bc9fbf7f5e1409234 to your computer and use it in GitHub Desktop.
This extnesion allows to get UIInterfaceOrientation from UIScreen. It is useful for cases when by some reasons UIStatusBar and UIDevice.current.orientation are not available e.g. iMessage extension target in iOS 10.
This file contains 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 point = coordinateSpace.convert(CGPoint.zero, to: fixedCoordinateSpace) | |
if point == CGPoint.zero { | |
return .portrait | |
} else if point.x != 0 && point.y != 0 { | |
return .portraitUpsideDown | |
} else if point.x == 0 && point.y != 0 { | |
return .landscapeLeft | |
} else if point.x != 0 && point.y == 0 { | |
return .landscapeRight | |
} else { | |
return .unknown | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment