PDA

View Full Version : Rotate View That Gets Presented From Nav Controller




newtoiphonesdk
Sep 15, 2012, 03:23 PM
My root view is a Tab Bar Controller.

In this tab view, I do not want any tabs to rotate. However, some of the Tab Bar Items are Navigation Controllers, that present different pdf documents. I would like those to rotate. However, I set the ViewController Classes for those views to return YES on shouldAutorotate method, yet they refuse to rotate.

I present them using
[self.navigationController pushViewController:_webViewController animated:YES];


_webViewController is allowed to rotate, but won't.

I have also tried presenting Controller Modally, but that will not work either. Any thoughts?



ArtOfWarfare
Sep 15, 2012, 11:45 PM
Unless I'm mistaken, rotation limits are kind of inherited, aren't they?

So if one view in the hierarchy can't have a certain rotation, anything under it also can't have that rotation. So either your tabs have to rotate or nothing can. I think. It seems like I had that issue a month or two ago and that was my finding.

newtoiphonesdk
Sep 16, 2012, 12:16 AM
Unless I'm mistaken, rotation limits are kind of inherited, aren't they?

So if one view in the hierarchy can't have a certain rotation, anything under it also can't have that rotation. So either your tabs have to rotate or nothing can. I think. It seems like I had that issue a month or two ago and that was my finding.
Yet there are other apps that get by this like Twitter. In iPhone, if you click a tweet and then a URL in that tweet, a controller gets pushed that can rotate, while nothing else can.

xStep
Sep 16, 2012, 05:28 PM
As I understand it, you want only certain elements to rotate while the tab bar it self stays in place. I do this in my CameraTime (http://itunes.apple.com/us/app/cameratime/id488502785?mt=8) app. See the first two screen shots. Notice how the i and record buttons always are vertical.

I learned the trick via Stackoverflow from this post (http://stackoverflow.com/questions/730799/rotating-the-iphone-and-instantiating-a-new-uiviewcontroller/893785#893785). In case you are not taken to the best answer, the responder was Corey Floyd.

The key is setting up the device to generate rotation notifications, listen for them, and act upon them.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

When you do have rotation issues, it may be a good idea to review Why won't my UIViewController rotate with the device? (http://developer.apple.com/library/ios/#qa/qa2010/qa1688.html)

Apple also has a WWDC 2012 video titled "Session 240 - Polishing Your Interface Rotations".