0

For some reason I need to insert UITabBarController into conatiner view.

When UITabBarController is presented itself (VC with container view is skipped) it works perfectly and everything is being showed. But when I insert it into UIView like below UITabBar exists in Debug View Hierarchy but it is not visible in the app. In both cases attributtes of UITabBar in object inspector are the same.

private var tabBar: TabBarController!
@IBOutlet private var tabBarContainer: UIView! 
...
addChildViewController(tabBar)
tabBarContainer.addSubview(tabBar.view)
tabBar.didMove(toParentViewController: self)
kkiermasz
  • 464
  • 2
  • 15
  • 1
    It might be a pretty trivial, but it might be the reason of the issue: Have you checked that `UITabBarController` view has the same frame as the container view frame? (`tabBar.view.frame = view.frame`) – Ahmad F Feb 25 '19 at 13:31
  • @AhmadF I think you're right. It's problem with a frame. But take a look at my [Hierarchy Inspector](https://imgur.com/a/kg5FXys). The selected view is the container view and the next one on the stack is TabBarController. As you can see they are not equally placed on the screen. I did tabBar.view.frame = tabBarContainer.frame right before adding child view controller. – kkiermasz Feb 25 '19 at 13:51

1 Answers1

0

Okay, so I've figured it out. There are two ways to fix it:

1:

addChildViewController(tabBar)
tabBar.view.frame = tabBarContainer.bounds
tabBarContainer.addSubview(tabBar.view)
tabBar.didMove(toParentViewController: self)

2:

addChildViewController(tabBar)
tabBarContainer.addSubview(tabBar.view)
tabBar.view.translatesAutoresizingMaskIntoConstraints = false
tabBarContainer.translatesAutoresizingMaskIntoConstraints = false
tabBarContainer.snp.makeConstraints { make in
    make.bottom.equalTo(tabBar.view.snp.bottom)
    make.top.equalTo(tabBar.view.snp.top)
    make.left.equalTo(tabBar.view.snp.left)
    make.right.equalTo(tabBar.view.snp.right)
}
kkiermasz
  • 464
  • 2
  • 15