0

am facing a strange problem with the UI. Please find below details.

  • I created a sample demo project to showcase the issue. The requirement is pretty simple (Attached screen shots too). The app starts with a ViewController which is a UINavigationController, so it shows a NavigationBar.
  • A UISegmentController of 2 elements has added to the UINavigationBar.
  • There are 2 child TableViewControllers which will be shown for each segment selection.
  • Each ViewController is added using NSLayoutConstraints. And every time, older child VC will be removed and new one will be added instead of hiding and showing. Though we don't create the VC object every time. It has a strong reference
  • Child VCs are added to RootVC's view instead of having a ContainerView. Tried ContainerView also but same result.

Now the problem is, the second child VC is always placed under the Navigation bar(Please refer the screen shot attached). But the first one is perfectly fine as its laid below the NavigationBar. if I set the NavigationBar translucent property to "NO", both works fine as expected. But with NavigationBar translucent property as "YES", only the first one will be laid properly not the second one. It doesn't matter which ChildViewController(firstVC or secondVC), it happens for the childVC added after the first one. Any insights to this strange issue? I've created a sample demo project if you guys want to check whats going on there..

Thanks in advance..

First VC Second VC

Hadhi
  • 66
  • 9
  • Why dont you add one UIView in rootVC and add your viewcontrollers view to your UIView.. i mean to say use container view – karthikeyan Mar 03 '17 at 09:07
  • https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/ – karthikeyan Mar 03 '17 at 09:09
  • Hi @karthikeyan, Thanks for your response. I've used ContainerView also and mentioned the same in the post. But still the problem exist. And I repeat that, if the NavigationBar translucent property is set to NO, all works fine.. – Hadhi Mar 03 '17 at 09:13
  • 1
    Its working fine with container view.you need to disable automaticallyAdjustsScrollViewInsets – karthikeyan Mar 03 '17 at 09:36
  • https://github.com/karthisiva/TestChileVC – karthikeyan Mar 03 '17 at 09:43
  • Yes!!!.. That solves the issue.. So with a ContainerView and disabling automaticallyAdjustsScrollViewInsets works fine.. Thanks very much.. – Hadhi Mar 03 '17 at 10:18

2 Answers2

1

Did you disable the option : Auto adjust scrolls inset ? it is buggy and apply only to the first Scrollview of you view controller

CZ54
  • 5,488
  • 1
  • 24
  • 39
  • 1
    Yes!!!.. That solves the issue.. So with a ContainerView and disabling automaticallyAdjustsScrollViewInsets works fine.. Thanks very much.. – Hadhi Mar 03 '17 at 10:18
0

If you want to move your scrollview below the navigationBar,

Please set the viewControllers property self.automaticallyAdjustsScrollViewInsets = false;