如何修复导航栏下的视图 swift

how to fix view under navigation bar swift

我使用 EzPopup 库制作弹出窗口,当我将弹出窗口放在导航栏下时出现问题。 这是我的代码

@IBAction func showTopRightButton(_ sender: Any){
    guard let pickerVC = pickerVC else { return }

    pickerVC.delegate = self

    let popupVC = PopupViewController(contentController: pickerVC, position: .topRight(CGPoint(x: 0, y: navigationController!.navigationBar.frame.height+20)), popupWidth: 100, popupHeight: 200)

    popupVC.cornerRadius = 5
    present(popupVC, animated: true, completion: nil)
}

我遇到了像我的图片这样的问题 enter image description here

如何在 iphone x 和 iphone x

中制作相同的内容

在 iPhone X 纵向模式下,状态栏更高 — 44 pts,而不是 20 pts

您还需要添加 statusBar 框架高度。试试下面的代码:

//1.0 Get the Top bar height
let topBarHeight = UIApplication.shared.statusBarFrame.size.height + (self.navigationController?.navigationBar.frame.height ?? 0.0)

let popupVC = PopupViewController(contentController: pickerVC, position: .topRight(CGPoint(x: 0, y: topBarHeight)), popupWidth: 100, popupHeight: 200)

您可以阅读有关 UILayout 的更多信息here