LoginSignup
8
8

More than 5 years have passed since last update.

iOSのマルチデバイス対応 UITraitCollection

Posted at

iOS8で新しく作られたUITraitCollectionについて。

・UITraitCollection というクラスを用いてデバイス種別(iPhone/iPad)やタテヨコの Size Class (Compact / Regular)をそれぞれ取得するようになった。 
→ http://ka-zoo.net/2014/09/ios8-issues-and-more/

・今まで使っていた
[[UIScreen mainScreen] bounds].size.width
[[UIScreen mainScreen] bounds].size.height
は、
iOS7 の 4 inch iPhone では方向によらず(320, 568)だが、
iOS8 では Portrait時 (320, 568)、Landscape時 (568, 320) となる。
Viewのフルスクリーン指定・判定など、方向に拠らないコードになっている場合は注意が必要。 
→同ページ

・デバイスの種類や向きなどを判定したい場合は、View Controller から取得した UITraitCollection オブジェクトと自分で生成した UITraitCollection オブジェクトを比較します。
また、UITraitCollection は5つのコンビニエンスコンストラクタから生成することができます。各プロパティを引数にセットできるほか、既存の UITraitCollection オブジェクトの配列から生成できるコンビニエンスコンストラクタもあります(Compact と Regular が混合している場合は Regular が優先的にセットされます)。
→ http://dev.classmethod.jp/references/ios8-trait-collection/

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