Safe area is not updated after UIViewController.viewWillDisappear is called

To me it looks like the safe area of a view is not updated after the owning view controller's .viewWillDisappear() method is called.

Is this intended or a bug in the framework?

The issue is easily visualised by creating a custom UIViewControllerTransitioningDelegate that animates a smaller view in one view controller, to full screen size in another (constrained to safe areas). Then the safe areas will expand as the present animation goes on (as expected), but will not shrink as the dismiss animation goes on (not expected!). The expected behaviour would be that the safe area expands during the present animation, and shrinks during the dismiss animation.

The gif below shows the unexpected behaviour. The grey area of the presented view controller is the safe area.

I've attached the code I used to visualise this problem. ViewController.swift presents MyViewController.swift using FullScreenTransitionManager.swift

Accepted Reply

This is expected. Transitions in particular are meant to have relatively stable metrics (it would be odd for a view that is dismissing to suddenly pin at the safe area and then vanish, when it is meant to slide offscreen entirely for example).

In particular, if a view controller is not in the appearing state (between when we call -viewWillAppear: and -viewWillDisappear:) then we don't update its view's safe area, specifically as transitions usually occur between the will/did states (transition in occurs between willAppear and didAppear, transmission out between willDisappear and didDisappear).

  • Alright! Good to know :) Thanks a lot for the answer!

  • Could there be an exception if the original safe area inset is zero? The issue I encountered: during a "pop" transition of UINavigationController, my app adds a child view controller to the top view controller in response to an async network download, however that newly added child's view has its content layout in mess, because its safe area inset is zero. The layout will restore to normal condition only after user cancel the pop transition and start dragging on child view's table view.

Add a Comment

Replies

This is expected. Transitions in particular are meant to have relatively stable metrics (it would be odd for a view that is dismissing to suddenly pin at the safe area and then vanish, when it is meant to slide offscreen entirely for example).

In particular, if a view controller is not in the appearing state (between when we call -viewWillAppear: and -viewWillDisappear:) then we don't update its view's safe area, specifically as transitions usually occur between the will/did states (transition in occurs between willAppear and didAppear, transmission out between willDisappear and didDisappear).

  • Alright! Good to know :) Thanks a lot for the answer!

  • Could there be an exception if the original safe area inset is zero? The issue I encountered: during a "pop" transition of UINavigationController, my app adds a child view controller to the top view controller in response to an async network download, however that newly added child's view has its content layout in mess, because its safe area inset is zero. The layout will restore to normal condition only after user cancel the pop transition and start dragging on child view's table view.

Add a Comment