0

I've got a UIViewController (VC) nested in UIPageViewController in a UINavigationController in a UITabBarController (UIViewController < UIPageViewController < UINavigationController < UITabBarController).

Since I'd like to use the entire screen for photos in my VC, the frame should be covering the entire screen as well. A UIImageView shall be added as a subview to the view of my VC and due to a couple of other reasons I want the user to make the tabBar disappear using animations (navigationController?.setNavigationBarHidden(true, animated: animated) is used in my UIPageViewController to hide the navigation bar). Hiding the tabBar via animations seems to be a little harder in my case, however:

When I used animations to hide the bar I noticed that the view in the VC is cut off by the height of the tab bar. I was curious what view was above the bar and played with the backgroundColors in the parent views, i.e. UINavigationController and UIPageViewController and managed to find out that this was the UINavigationController. In a previous project I used edgesForExtendedLayout = [] and it did what I desire now. I've tried using it in individual controllers and in many controllers at the same time. Nothing's worked so far.

To get the height of the view I used viewDidLayoutSubviews (it was smaller than it was supposed to be) and I managed to correct it using viewWillLayoutSubviews (print tells me its height is equal to UIScreen.main.bounds.height). Nonetheless, it isn't visible and therefore probably clipped by (apparently) the UINavigationController.

Does anyone know what's causing the problem and how it could possibly be fixed? I'd appreciate your help!

EDIT: Also tried setting view.frames equal to one another (VC's = PageVC's and PageVC's = NavigationVC's) didn't do the job, either. Debugging the view hierarchy indicates that the VC.view and PageVC.view are still cut off.

Moritz
  • 745
  • 1
  • 10
  • 32
  • 1
    Is your tabBar translucent? Setting it to translucent allows embedded controllers to "grow" beneath it, while opaque bars usually make your controllers "smaller". – TomQDRS Aug 30 '18 at 21:53
  • @TomQDRS managed to find a solution albeit not a very elegant one – Moritz Aug 31 '18 at 15:08
  • there are ways around the transparency of translucent bars, that's how I realized them. Good to hear you found your own solution - regardless of what you're doing, it's never not going to be hack-y – TomQDRS Aug 31 '18 at 15:13

1 Answers1

0

To be honest, I didn't try setting it to translucent as proposed in the first comment because I really wanted to keep it opaque. And I did manage to do it, although in a rather less elegant way. So here the solution to my problem:

Recall the VCs were nested in the following way: UIViewController < UIPageViewController < UINavigationController < UITabBarController. I tried edgesForExtendedLayout = [] in every one of them, even combinations but none of them worked. In an old project however, I put an additional VC between the PageVC and the NavVC, essentially changing the order of the views to: UIViewController < AdditionalUIViewController < UIPageViewController < UINavigationController < UITabBarController. Setting edgesForExtendedLayout = [] in this additional controller fixed it.

I'm happy the problem is solved. Yet I still cannot put my finger on why the problem occurred. If anyone's got an idea, I'd be glad to hear it!

Moritz
  • 745
  • 1
  • 10
  • 32