Safe area guide top anchor lost after force change orientation

Hi, I wrote a simple auto layout constraint below and used a force change orientation method to present a full-screen landscape view controller.

imageView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 16)

After the landscape view controller is dismissed, the safe area guide seems broken, the top safe area insets change to zero, and call layoutIfNeeded() won't fix this issue. The only way to fix this is back to Home Screen and reopen the app. This problem occurred on the iPhone SE simulator, newer devices with a notch don't have this issue. Does anybody know how to fix this?

func forceOrientation(orientation: UIInterfaceOrientation) {

    let value = orientation.rawValue

    if #available(iOSApplicationExtension 16.0, iOS 16.0, *) {

        let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene

        var interfaceOrientations: UIInterfaceOrientationMask = []

        switch orientation {

        case .portrait:

            interfaceOrientations = .portrait

        case .landscapeLeft:

            interfaceOrientations = .landscapeLeft

        case .landscapeRight:

            interfaceOrientations = .landscapeRight

        case .portraitUpsideDown:

            interfaceOrientations = .portraitUpsideDown

        case .unknown:

            interfaceOrientations = .portrait

        @unknown default:

            interfaceOrientations = .portrait

        }

        windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: interfaceOrientations))

    } else {

        UIDevice.current.setValue(value, forKey: "orientation")

        UINavigationController.attemptRotationToDeviceOrientation()

    }

}
Safe area guide top anchor lost after force change orientation
 
 
Q