问题
I'm working on a iPad application that should support all orientations. I am not using nibs. I have a UIWindow that lays out four views:
Two of which take up full width, but not much height.
The other two take up the bulk of the height, and share the same origin.x. They do not overlap.
I designate one view as the main window's subview, and subview the rest to window.view.
The issue: after rotation, it appears as thought the status bar's frame sticks to its original position (top of portrait orientation) regardless of orientation. Although, the status bar does rotate.
I did note red-glasses informative article. But, this doesn't appear quite the same problem. This is different in the sense that red-glasses approach managed to cover the status bar strip by setting the main view as the window's subview. I have taken this approach, but the issue persists.
I've tried reframing and recentering the window.view frame in willRotateToInterfaceOrientation:: with little luck. I have verified that the new frames/centers are what I would expect. It appears as though there is some reframing going on in the background.
I'm not sure what to think at this point... I'm hoping that someone can shed some light on this subject.
回答1:
Finally! I got the views aligning coherently.
Turns out the problem was in didFinishLaunchingWithOptions:
The problem was I was initializing my UIWindow via initWithFrame:[[UIScreen mainScreen] applicationFrame];
When I initialized using init instead the views were positioned as expected. It only works when I leave the reframing code in willRotateToInterfaceOrientation: (as noted above).
In willRotateToInterfaceOrientation:, I calculated and set the correct frame for each view, then integrated the transformation into the rotation animation using UIView animateWithDuration:::::
I set the new frames in the second to last selector argument to animateWithDuration.
Hope this helps someone...
来源:https://stackoverflow.com/questions/7936536/statusbar-frame-sticks-to-portrait-orientation-and-occludes-window-view