-1

I add ViewController above the tabBar like this

 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

the size of tabBar i get like this:

tabBarHight = tabBarController?.tabBar.frame.size.height

This is works for all iPhones but not for iPhone X how to fix this moment ?

enter image description here

Kamran
  • 14,987
  • 4
  • 33
  • 51

2 Answers2

7

In my case the right way to get this point is not get the safeArea but get point of tabBarFrame like this

let topTapbarPosition = tabBarController?.tabBar.frame.minY

after that use it like this

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

                                           width: view.bounds.width, height: cardHeight!)

It will be work fine at all models of iPhones

1

You should position the added view via Auto Layout, instead of setting the frame.

But if you really need to work with pixel sizes, you can access to bottom padding via

view.safeAreaInsets.bottom

You should also have a look at: https://stackoverflow.com/a/46831519/2133377

messeb
  • 364
  • 2
  • 11
  • can you give an example how to add ViewController via Auto Layout? And how Can i use view.safeAreaInsets.bottom in my case? set Y at view.safeAreaInsets.bottom – Vladimir Pchelyakov Nov 11 '18 at 13:38
  • For Auto Layout have a look at: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/index.html For the solution with `view.safeAreaInsets.bottom`. you have to replace `tabBarHight` with `view.safeAreaInsets.bottom` – messeb Nov 11 '18 at 22:16
  • this will be works only in viewDidLayoutSubviews(), but I need this value in moment of ViewDidLoad. – Vladimir Pchelyakov Nov 12 '18 at 08:33
  • Answer don't solve my problem, I need to know this value at the viewDidLoad. Have you any Ideas? – Vladimir Pchelyakov Nov 24 '18 at 08:50
  • 1
    But viewDidLoad() is the wrong place to determine the size of views. Therefore you should use Auto Layout or place the calculation in viewDidLayoutSubviews(). – messeb Nov 25 '18 at 12:28