iOS: App broken until screen Locked/Unlocked

I am trying to build an app for iOS, and I can successfully get it on my phone through testflight. But the “constrain aspect ratio” seems to break when I open the app. The game only runs correctly after I lock and unlock the iPhone screen. Can anyone explain why this might happen or what happens to the code when the phone screen is locked and unlocked? Thanks.