UIScreen.MainScreen.Bounds not correct until the device is rotated
I've done a search on this but can't find anything. In my monotouch app I call UIScreen.MainScreen.Bounds to get the width / height of the screen. When I first start the app in landscape mode the width is returned as 768 and the height 1024 (ie portrait). Once I rotate the device once, all is well.
Has anyone got a work around for this? I notice that if I add a UIScrollView to be my controller's main View that gets sized correctly by IOS, so the information seems to be there, is this a bug wi开发者_开发知识库th monotouch?
This happens on the simulator and the device (iPad).
It's my understanding that when an app launches, iOS assumes that the device is in portrait mode, so that's why it reports the starting bounds as 768 x 1024. If you are holding the device in landscape mode when the app launches, iOS will launch in portrait mode and then execute a rotation to landscape mode if the view controller allows it. This happens before the view controller's View appears on the screen. The result is that it appears to the user that the app is starting in landscape mode but really it's starting in portrait mode and instantly rotating to landscape mode behind the scenes. I think you'll see this happening if you sprinkle your rotation code with "Console.WriteLine(UIScreen.MainScreen.Bounds)". Similarly strange things happen to UIScreen.MainScreen.ApplicationFrame.
精彩评论