Last active
February 1, 2019 03:51
-
-
Save jumplee/6f0a3af4ee5a412fc6e201e776321cef to your computer and use it in GitHub Desktop.
change orientation
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
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