LoginSignup
8
6

More than 5 years have passed since last update.

iPhoneの画面回転(Upside Down)

Posted at

iPhoneの画面を逆さにも対応させたい時にDevice Orientationを変えるだけではできなかったので、のやり方をまとめます。

普通にやると

通常はプロジェクト作成するとDevice Orientationのうち以下3つがデフォルトでチェックされています。
・Portrait(縦)
・Landscape Left(横向き 左回転)
・Landscape Right(横向き 右回転)
逆向きも対応したい場合は
・Upside Down(縦 逆向き)
にもチェックを入れればOKかと思いきやそうもいきません。
スクリーンショット 2016-07-07 22.52.00.png
この状態で実行すると逆向きになってくれません。↓
beforeImg.gif

こうやるとできる

ViewControllerでメソッドを1つオーバーライドすると逆向きにも対応できます。

ViewController.swift
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        // 許可する画面を追加
        let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Portrait,
                                                       UIInterfaceOrientationMask.PortraitUpsideDown,
                                                       UIInterfaceOrientationMask.LandscapeLeft,
                                                       UIInterfaceOrientationMask.LandscapeRight]
        return orientation
    }

これで実行するとうまくいきます↓
afterImg.gif

8
6
2

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
8
6