LoginSignup
4
5

More than 3 years have passed since last update.

向きの一覧

デバイスの向き一覧はこちらの記事にあります。
Orientationのパラメータのまとめ(UIDeviceOrientation, UIInterfaceOrientation)
スクリーンショット 2020-09-17 6.01.56.png

起動してすぐはデバイスの向きが取れない

UIDevice.current.orientationでデバイスの向きは取れるのですが、アプリを起動してすぐは.unKnownを返すようになっています。

起動してすぐの向きはUIInterfaceOrientationで確認できます。

iOS12まで

UIApplication.shared.statusBarOrientation

iOS13以降

self.view.window?.windowScene!.interfaceOrientation

*ただし、画面内のインターフェイスの向きなので、
viewが現れていない状態でUIInterfaceOrientationを確認するとnilになります。
viewDidAppear ~ viewWillDisAppear の間で確認するようにします。
また、デバイスを寝かせて置いた状態(.faceUp, .faceDown)は認識できません。


Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
MLBoysチャンネル
Medium

相棒
note

contact:
rockyshikoku@gmail.com

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