Help us understand the problem. What is going on with this article?

デバイス回転の制御

More than 5 years have passed since last update.

背景

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

UISupportedInterfaceOrientations

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

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

回転制御方法

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

ソースコード

https://github.com/bolobob/RotateSample

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
によると、アプリを起動するときに取りうる方向を指定しておくものらしい。

bolobob
sencorp
幼稚園・保育園向けインターネット写真サービス「はいチーズ!」を提供しています。
https://sencorp.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした