Get safe area inset top and bottom heights

后端 未结 15 1432
长发绾君心
长发绾君心 2020-11-30 17:30

On the new iPhone X, what would be the most proper way to get both top and bottom height for the unsafe areas?

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 17:41

    For those of you who change to landscape mode, you gotta make sure to use viewSafeAreaInsetsDidChange after the rotation to get the most updated values:

    private var safeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    
    override func viewSafeAreaInsetsDidChange() {
            if #available(iOS 11.0, *) {
                safeAreaInsets = UIApplication.shared.keyWindow!.safeAreaInsets
            }
    }
    

提交回复
热议问题