LoginSignup
11
9

More than 5 years have passed since last update.

safeAreaInsets.top と status bar のメモ

Last updated at Posted at 2017-09-22

safeAreaInsets.top と status bar のメモ

OS Device AppDelegate?.window?
.safeAreaInsets.top
UIApplication.shared
.statusBarFrame
iOS10 iPhone7 Plus Port - 取得できない - (0.0, 0.0, 414.0, 20.0)
iOS10 iPhone7 Plus Land - 取得できない - (0.0, 0.0, 0.0, 0.0)
iOS10 iPad Port - 取得できない - (0.0, 0.0, 768.0, 20.0)
iOS10 iPad Land - 取得できない - (0.0, 0.0, 1024.0, 20.0)
iOS11 iPhone6 Plus Port 0.0 (0.0, 0.0, 414.0, 20.0)
iOS11 iPhone6 Plus Land 0.0 (0.0, 0.0, 0.0, 0.0)
iOS11 iPhoneX Sum Port 44.0 (0.0, 0.0, 375.0, 44.0)
iOS11 iPhoneX Sum Land 0.0 (0.0, 0.0, 0.0, 0.0)
iOS11 iPad Port 0.0 (0.0, 0.0, 768.0, 20.0)
iOS11 iPad Land 0.0 (0.0, 0.0, 1024.0, 20.0)

XだけsafeAreaInsetsが設定されている。
変にsafeAreaLayoutGuideとか使わず親Viewに対してstatusBarFrame.heightでオリジナルトーストの位置を調整。

こんな感じのグローバル変数作って制約設定時に利用。

///
/// Safe Area Insets
///
var SAFE: UIEdgeInsets {
    get {
        if #available(iOS 11.0, *) {
            if let insets = AppDelegate?.window?.safeAreaInsets {
                return insets
            }
        }
        return UIEdgeInsets.zero
    }
}
11
9
2

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
11
9