SafeArea breaks after device orientation change

I'm having an issue where on my iPhone 13 (no other device seems to have this issue) where the safe area gets applied in one orientation but the minute you change orientation when the app is running, the safe area is inaccurate.

iPhone 13 reported:

  • A safe area after opening the app in portrait of: (X:0, Y:102, Width: 1170, Height: 2289)
  • A safe area after opening the app in landscape of: (X:141, Y:63, Width: 2250, Height: 1107)
  • A safe area after opening the app in portrait but rotating to landscape after load of: (X:0, Y:102, Width: 2532, Height: 927)

I'm not sure why the values of the safe area in landscape would be different from opening the app vs changing orientation when the app is running. Any ideas?

Code snippet:

public void ApplySafeArea(Rect pSafeArea) {
        if (_trans == null) {
            _trans = transform as RectTransform;
        }

        Vector2 anchorMin = pSafeArea.position;
        Vector2 anchorMax = pSafeArea.position + pSafeArea.size;
        anchorMin.x /= Screen.width;
        anchorMin.y /= Screen.height;
        anchorMax.x /= Screen.width;
        anchorMax.y /= Screen.height;

        _trans.anchorMin = anchorMin;
        _trans.anchorMax = anchorMax;
    }

Where pSafeArea is Screen.safeArea

Is it on device or on simulator ?

Which versions of Xcode (13 or 13.1 or 13.2), iOS ?

Could you show the code you use to get the size ? Where do you run it ?

In viewDidLoad ? Or elsewhere ?

Could you show the exact code for where you use Screen.safeArea (the calling func)?

I probably miss something, but I cannot find safeArea in doc.

This is an issue that has been discussed on the Unity forums.

https://forum.unity.com/threads/unity-safearea-is-inconsistent-between-different-starting-rotations.1173764/

SafeArea breaks after device orientation change
 
 
Q