Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Status Bar rotates and view remains portrait

My rootViewController is a UITabbarController and contains UINavigationControllers.

In order to restrict rotation, since iOS6, on some but not all views, I have subclassed both of the these controllers to respect the shouldAutorotate response of their topmost or visible view.

This all works just perfectly... most of the time.

In one case, starting from a view (UITableviewController) that does not allow rotation.

I push a view that does allow autorotate, rotate to landscape then back to portrait.

Then when I pop the view, all appears well.

But now if I rotate the device, the status bar alone rotates, leaving a blank space at the top and covering a part of the left side of the current view. The current view does not rotate (as it should not). Only the status bar rotates, back and forth. The view remains responsive, receives touches and works as normal, doesn't resize or respond to rotation in any way (as it should not).

This behavior continues until I kill and restart the app. Once it happens I have found no other way to make it stop. On restart all works properly again and will work properly for an indeterminate duration. I can sit there pushing, popping, rotating back and forth to my hearts content with no issues.

I have never been able to recreate this in simulator.

It happens for no apparent reason, I cannot make it happen. I'd say 85% of the time it works properly. I thought I had it fixed many times when it did not occur for days or even weeks. Then, out of the blue it happens again.

I cannot find a post in any forums which describe this behavior, so I am not finding even a place to start to debug. How could the status bar swing from top to side and the view does not resize or rotate or respond in any way. If I knew how to make that happen, I would have a place to start.

like image 200
Dean Davids Avatar asked Aug 12 '13 14:08

Dean Davids


1 Answers

I experienced the same problem when adding a subclassed UIWindow (in my case, a status bar overlay).

The solution was to set the rootViewController of this new UIWindow to a subclassed UIViewController that had -(BOOL)shouldAutorotate implemented. This prevented the status bar from rotating when it wasn't supposed to.

like image 167
adamup Avatar answered Oct 01 '22 03:10

adamup