9

I have a rootViewController that has a child view controller (fullScreenViewController) whose view, from time to time, is displayed above the view (but as a subview) of the rootViewController, taking up the full screen.

i.e. rootViewController.addChildViewController( fullScreenViewController ) rootViewController.view.addSubview( fullScreenViewController.view )

This "full screen presentation" is done with constraints updates, not by using present() (There's good reason for this).

When I first initialize fullScreenViewController and add it as a child view controller of rootViewController, then update the constraints so that it is on screen, the safeAreaInsets are all set properly.

However, when, later on, my rootViewController actually does present() a modal VC, and that VC is dismiss()ed, the safeAreaInsets on the fullScreenViewController are no longer correct, and the content in the fullScreenViewController slides up on top of the status bar.

How can I force the safeAreaInsets on fullScreenViewController to be recalculated properly, so that they match the rootViewController the way they do after setup?

According to the documentation, the rootViewController should be setting the safeAreaInsets properly on all of its childViewControllers, but this doesn't seem to be the case.

Safe Area Insets Correct

Safe Area Insets Incorrect

Jeff
  • 4,751
  • 5
  • 31
  • 35
  • I have the exact same issue, displaying a modal above the container view controller will mess the child's safe area insets. Where you able to find the reason for this or a fix? – amadour Sep 03 '18 at 14:29

1 Answers1

5

I had the exact same issue with a child view controller's safeAreaInsets not being properly refreshed after a presentation changed the safe area.

I found that the issue was resolved by making the child's view a direct subview of the parent's view, when before it was a subview of a subview. I guess UIKit code is happier when child VC's views are direct subviews of parent's.

If you can refactor your view hierarchy to this configuration (if not already the case) this might do it.

amadour
  • 1,600
  • 11
  • 20
  • I ended up refactoring most of my view hierarchy, and something in there fixed it for me. I'll have to play with your solution to see if that is the particular issue I'm having. Seems promising though; glad you got it fixed! – Jeff Sep 04 '18 at 15:48
  • Does not work in my case. – Alexander Algashev Dec 29 '22 at 11:42