Skip to content

Instantly share code, notes, and snippets.

@jumplee
Last active February 1, 2019 03:51
Show Gist options
  • Save jumplee/6f0a3af4ee5a412fc6e201e776321cef to your computer and use it in GitHub Desktop.
Save jumplee/6f0a3af4ee5a412fc6e201e776321cef to your computer and use it in GitHub Desktop.
change orientation
test{
func changeOrientation(){
guard let slf = self else {
return
}
let isPortrait=slf.isScreenPortrait()
print("isPortrait===>"+String(isPortrait))
let isPortrait=slf.isScreenPortrait()
print("isPortrait===>"+String(isPortrait))
if isPortrait {
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
UIApplication.shared.setStatusBarHidden(false, with: .fade)
UIApplication.shared.statusBarOrientation = .landscapeRight
} else {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UIApplication.shared.setStatusBarHidden(false, with: .fade)
UIApplication.shared.statusBarOrientation = .portrait
}
}
/// detect screen is Portrait
public func isScreenPortrait() -> Bool{
return UIDevice.current.orientation.isValidInterfaceOrientation
? UIDevice.current.orientation.isPortrait
: UIApplication.shared.statusBarOrientation.isPortrait
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment