David Seek David Seek - 1 month ago 7
Swift Question

How to use UITabBarController with NavigationBar and ScrollView?

I am using SLPagingView to have a moving NavigationBar in my Swift 3 project.

enter image description here

The controller is a

SubClass
of
UIViewController
with a
ScrollView
.

I want to use a
UITabBarController
as one of the embeddeded
UIViewControllers
. The problem is, that my TabBar is missing:

The white bar within the green controller shows the problem:

enter image description here

Current outcome on the Simulator (iPhone 7 Plus):

enter image description here

I guess the
TabBar
is missing in size of the
NavigationBar
+ the
StatusBar
. In other controllers I'm using
UITableViews
with inset. How do I display the
UITabBar
in the current situation? Help is very appreciated.

Edit:

As a current work around, I have the "solution" to move the
TabBar
to a desired position.

class TabC: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()
let statusBarHeight = UIApplication.shared.statusBarFrame.height
let screenSize: CGRect = UIScreen.main.bounds
let tabBarFrame = CGRect(x: 0, y: (screenSize.height - 88 + statusBarHeight), width: screenSize.width, height: 0)

self.tabBar.frame = tabBarFrame
}
}


The perfect position is 2 times a
NavigationBar
(
2x 44 = 88
) minus
statusBarHeight
. It works on iPhone 5S, 6, 7 Plus. Every time the same position.

But why 2 times a
NavigationBar
(minus
statusBarHeight
)
and is this the best approach?

enter image description here

Joe Joe
Answer

Note: Below answer based on the conversation with question owner.

From the Post: The perfect position is 2 times a NavigationBar (2x 44 = 88). It works on iPhone 5S, 6, 7 Plus. Every time the same position.But why 2 times a NavigationBar?

SLPagingView bar is a custom UIView that acts like a sliding navigationBar.From his tabBarController.he programmatically hiding the status bar..

Calculation:

According to his SLPagingView controller there is no navigationBar(44) and tabBar(44) thats make 2 x 44 = 88..

From his tabBarController his calculation should be like below

 UIApplication.shared.statusBarFrame.height + UINavigationController().navigationBar.frame.height + UINavigationController().toolbar.frame.height + tailingSpace between the barView to tabBar(8 as he mentioned)