swift ios macCatalyst app does not load some views on startup on macOS Monterey

Hi everyone,  since the release of the new macOS Moterey operating system (12) my MacCatalyst application does not load some views at startup until I resize the window or change focus.

If I look at XCode's Debug View Hierarchy these views are not present.

If, on the other hand, I use the classic debug (while they are not shown) it turns out that they have the correct frame (origin and size), superviews and window.

To show them I have to resize the window (manually, using the mouse) or remove the focus from the app (for example by clicking on another window and then clicking the app window again).

Only after doing one of these two things are the views loaded. Has anyone experienced the same behavior? The application is developed in Swift only with UIKit and various Storyboards (without SwiftUI).

Thanks a lot to everyone.

Answered by Moleskyth in 702790022

I understand what happens.  If it can be useful to anyone ... 

For my UIViewControllers I use custom margins that take into account the minimum width of a scene.  I take this value like this: 

var minSceneWidth:CGFloat = 400
scenes.forEach { windowScene in
    if let w = windowScene.sizeRestrictions?.minimumSize.width {
        if minSceneWidth > w {
            minSceneWidth = w
        }
    }
}

Since the latest version of macOS the value "minimumSize.width" seems to be also "0" and this is not good for the calculation of my margins. 

Thank you all.

How are these views normally added to your app's interface? If you're adding them in a method such as viewDidLayoutSubviews, nextResponder, or traitCollectionDidChange:, keep in mind that these methods may not be called always at startup and you shouldn't rely on them to build your app's interface.

Accepted Answer

I understand what happens.  If it can be useful to anyone ... 

For my UIViewControllers I use custom margins that take into account the minimum width of a scene.  I take this value like this: 

var minSceneWidth:CGFloat = 400
scenes.forEach { windowScene in
    if let w = windowScene.sizeRestrictions?.minimumSize.width {
        if minSceneWidth > w {
            minSceneWidth = w
        }
    }
}

Since the latest version of macOS the value "minimumSize.width" seems to be also "0" and this is not good for the calculation of my margins. 

Thank you all.

swift ios macCatalyst app does not load some views on startup on macOS Monterey
 
 
Q