背景
開発中のiOSアプリケーションのマルチタスク対応を行った。
表示中の画面がiPadサイズか/iPhoneサイズかを判別するためにviewDidLoad
内でUITraitCollection
を参照したが、unspecified
になってしまい、期待した値が取得できなかった。

horizontalSizeClass | Apple Developer Documentation
The horizontal size class of the trait collection.
原因
UITraitCollectionはviewDidLoad
ではまだ値がセットされていない
解決策
viewWillAppear
で呼ぶことにした。
UI系の操作はviewDidLoadでやっちゃダメだ、ってそういえば前も覚えた気がするのに。
すっかり忘れていたよ、このポンコツ頭めっ!
こうやってブログに残しておけば忘れない…はず…!
参照

view.traitCollection.horizontalSizeClass returning undefined (0) in viewDidLoad
I'm using a UITextView inside a UIPageViewController, and I want to determine the font size based on the size class of the device. The first slide of the page ...
コメント