Get safe area inset top and bottom heights

后端 未结 15 1393
长发绾君心
长发绾君心 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:59

    None of the other answers here worked for me, but this did.

    var topSafeAreaHeight: CGFloat = 0
    var bottomSafeAreaHeight: CGFloat = 0
    
      if #available(iOS 11.0, *) {
        let window = UIApplication.shared.windows[0]
        let safeFrame = window.safeAreaLayoutGuide.layoutFrame
        topSafeAreaHeight = safeFrame.minY
        bottomSafeAreaHeight = window.frame.maxY - safeFrame.maxY
      }
    
    0 讨论(0)
  • 2020-11-30 17:59
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; 
    CGFloat fBottomPadding = window.safeAreaInsets.bottom;
    
    0 讨论(0)
  • 2020-11-30 17:59

    Objective-C Who had the problem when keyWindow is equal to nil. Just put the code above in viewDidAppear (not in viewDidLoad)

    0 讨论(0)
提交回复
热议问题