LoginSignup
4
1

More than 3 years have passed since last update.

Orientationのパラメータのまとめ[Swift](UIDeviceOrientation, UIInterfaceOrientation)

Last updated at Posted at 2019-06-19

向きと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じゃないとダメ
    }
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1