代码之家  ›  专栏  ›  技术社区  ›  Pablo Martinez

没有状态栏的导航栏与iOS11中的安全区域重叠

  •  1
  • Pablo Martinez  · 技术社区  · 7 年前

    我在iOS11中遇到了iPhoneX模拟器的问题。

    我有一个没有状态栏的viewcontroller。为此,我添加了:

    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    

    目前为止还不错,但导航栏与iPhoneX中的安全区域重叠。

    enter image description here

    我怎样才能解决这个问题?

    1 回复  |  直到 7 年前
        1
  •  6
  •   Pablo Martinez    7 年前

    最后,解决方案是使用 safeAreaInsets

    if (@available(iOS 11.0, *)) {
            UIEdgeInsets safeInsets = UIApplication.sharedApplication.delegate.window.safeAreaInsets;
            paddingTop = safeInsets.top;
    }
    

    enter image description here enter image description here