1
1

More than 1 year has passed since last update.

Swift 画面を強制的に回転させたい!

Posted at

回転のコードはこれ!

    override func viewDidLoad() {
        //右か左か判定
        if(UIDevice.current.orientation.rawValue == 4){
            UIDevice.current.setValue(4, forKey: "orientation")
        }
        //左横画面以外の処理
        else {
            //最初の画面呼び出しで画面を右横画面に変更させる。
            UIDevice.current.setValue(3, forKey: "orientation")
        }
    }

    //MARK: 回転設定
    override var shouldAutorotate: Bool {
        return true
    }
    //MARK: 横画面のみ許可
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.landscape
    }

これで任意の画面だけ強制的に回転するコードなのだが、

StoryBoardの該当画面のViewControllerのPresentation設定を

「Full Screen」

にしないと回転しない!

以上

1
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
1
1