LoginSignup
7
8

More than 5 years have passed since last update.

画面回転した後の画面サイズを正確に取得したい

Last updated at Posted at 2015-09-14

問題点

画面回転のNotificationを受け取って

self.view.bounds

とかすると画面回転前のビューのサイズが表示される。
ゆっくりやるとちゃんと出来るけど超速でくるくるやると画面サイズがおいついてこない

やりたいこと

  • 連続したorientationイベントが発生した場合でも正確な画面サイズを取得したい…

解決策

viewWillTransitionToSizeを使用します。

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
  println("\(size.width)")
  println("\(size.height)")
}

画面縦横の判別

UIDevice.currentDevice().orientation.isLandscape.boolValue
//画面が横だったら true
7
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
7
8