向きとrawValueの関係
UIInterfaceOrientationはDeviceではなくUIの向きである
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
UIDeviceOrientation と UIInterfaceOrientation
※enumは型のみ指定して値を入れない場合は0から代入される
public enum UIDeviceOrientation : Int {
case unknown //0
case portrait //1 //普通の縦向き
case portraitUpsideDown //2 //逆さ向き
case landscapeLeft //3 //homeボタンが右
case landscapeRight //4 //homeボタンが左
case faceUp //5 //地面に平行向き//スクリーンが上
case faceDown //6 //地面に平行向き//スクリーンが下
}
public enum UIInterfaceOrientation : Int {
case unknown //0
case portrait //1 //普通の縦向き
case portraitUpsideDown //2 //逆さ向き
case landscapeLeft //3 //homeボタンが左
case landscapeRight //4 //homeボタンが右
}
rawValue以外で取り出す方法
普通にrawValueでやるとこうなる
print(UIInterfaceOrientation.rawValue) //1
case名で取り出したい(ex. 1ではなくportrait)
→どの値か事前にわかってない場合はrawValue以外は無理
print(UIInterfaceOrientation.portrait) //portrait
強制的に値をセット(回転させる)
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.setValue(3, forKey: "orientation")
//landscapeLeft //homeボタンが右
//UIDevice.current.orientationを設定するのでforkeyはorientationじゃないとダメ
}