I have a scrollView contains 2 child viewController. You can see VC2 not layout properly.

I found if view is not yet visible onscreen.
`safeAreaInsets` is always 0. 

I can call `vc2.view.setNeedsLayout()` to fix this problem when scroll ended.
But the layout is not correct until scroll ended.

The [document](https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets) says 

> 
> If the view is not currently installed in a view hierarchy, or is not
>  yet visible onscreen, the edge insets in this property are 0.
> 
> 
> 

So how can I fix this situation.

[![enter image description here](https://i.stack.imgur.com/egxG8.gif)](https://i.stack.imgur.com/egxG8.gif)

Autolayout
[![enter image description here](https://i.stack.imgur.com/22TXk.png)](https://i.stack.imgur.com/22TXk.png)
[![enter image description here](https://i.stack.imgur.com/jz7J3.jpg)](https://i.stack.imgur.com/jz7J3.jpg)