5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

デバイス回転の制御

Last updated at Posted at 2015-04-25

背景

画面(ViewController)ごとに回転を制御したいとき、
とりあえず回転する可能性のある方向をすべて指定してから

UISupportedInterfaceOrientations

スクリーンショット 2015-04-25 23.51.33.png

ViewController
shouldAutoroate, supportedInterfaceOrientations
をオーバーライドして制御する方法しか知らなかった。
あまりスマートじゃないと感じたので別の方法を探してみた。

回転制御方法

以下のようにするとViewControllerごとに回転を制御できるようになる。

ソースコード

AppDelegate.swift

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
        if window?.rootViewController?.presentedViewController is ViewController2 {
            return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
        } else {
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }
    }

ではUISupportedInterfaceOrientationsって?

UISupportedInterfaceOrientations
によると、アプリを起動するときに取りうる方向を指定しておくものらしい。

5
5
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?