如何在 iPhone X 上获取 tabBar 的高度

Vla*_*kov -1 ios swift

我在ViewController上面添加tabBar这样的

 cardViewController = storyboard?.instantiateViewController(withIdentifier: "CardViewController") as? CardViewController
    addChildViewController(cardViewController)
    cardViewController.didMove(toParentViewController: self)

    view.addSubview(cardViewController.view)

    cardViewController.view.frame = CGRect(x: 0, y: view.frame.height - cardHandlAreaHight - tabBarHight,
                                           width: view.bounds.width, height: cardHight)

    cardViewController.view.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)

我得到的 tabBar 的大小是这样的:

tabBarHight = tabBarController?.tabBar.frame.size.height
Run Code Online (Sandbox Code Playgroud)

这适用于所有 iPhone 但不适用于 iPhone X 如何解决这个问题?

在此处输入图片说明

Vla*_*kov 7

在我的情况下,获得这一点的正确方法不是获得 safeArea,而是像这样获得 tabBarFrame 的点

let topTapbarPosition = tabBarController?.tabBar.frame.minY
Run Code Online (Sandbox Code Playgroud)

之后像这样使用它

cardViewController.view.frame = CGRect(x: 0, y: topTapbarPosion! - cardHeight!,

                                           width: view.bounds.width, height: cardHeight!)
Run Code Online (Sandbox Code Playgroud)

它适用于所有型号的 iPhone