Checking safeAreaInsets in viewWillTransition

Hi.

We use the viewWillTransition(to size: CGSize, with coordinator: any UIViewControllerTransitionCoordinator) function to update frames when user rotates / opens / folds an iPhone Duo. However we found that the safeAreaInsets are not always correct in the alongsideTransition block of the animate(alongsideTransition:completion:) funciton.

Here's the test code I wrote in a UIViewController:

    override func viewWillTransition(to size: CGSize, with coordinator: any UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        
        print(">>> before animate, view.frame: \(view.frame)")
        print(">>> before animate, view.safeAreaInsets: \(view.safeAreaInsets)")
        
        coordinator.animate { [weak self] _ in
            print(">>> in animate, view.frame: \(self?.view.frame)")
            print(">>> in animate, view.safeAreaInsets: \(self?.view.safeAreaInsets)")

            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {       
                print(">>> after 0.1, view.frame: \(self?.view.frame)")
                print(">>> after 0.1, view.safeAreaInsets: \(self?.view.safeAreaInsets)")
                print(">>> -------------")
            }
        }
    }

And here's the logs when I rotate an opened iPhone Duo from "portrait" to "landscape" (where the tab bar is placed on the trailing / right side of screen):

>>> before animate, view.frame: (0.0, 0.0, 669.0, 951.0)
>>> before animate, view.safeAreaInsets: UIEdgeInsets(top: 82.0, left: 0.0, bottom: 83.0, right: 0.0)

>>> in animate, view.frame: Optional((0.0, 0.0, 951.0, 669.0))
>>> in animate, view.safeAreaInsets: Optional(__C.UIEdgeInsets(top: 82.0, left: 0.0, bottom: 83.0, right: 0.0))

>>> after 0.1, view.frame: Optional((0.0, 0.0, 951.0, 669.0))
>>> after 0.1, view.safeAreaInsets: Optional(__C.UIEdgeInsets(top: 24.0, left: 0.0, bottom: 34.0, right: 84.0))
>>> -------------

In the alongsideTransition block I can get the correct view's frame, but the safeAreaInsets value is not correct. After a short delay of 0.1 seconds the safeAreaInsets becomes correct.

Is getting the wrong safeAreaInsets in the alongsideTransition block a normal behavior? When is the correct timing to detect view's frame and safeAreaInsets when rotation (or view size change) happens?

Checking safeAreaInsets in viewWillTransition
 
 
Q