1

Happy Memorial Day for those in America!

I am new to iOS and Objective-C programming; a few weeks ago I inherited an iPad app-in-development that was being designed for iOS 5. I now have everything working except the rotation in iOS 6. I know that iPad apps should rotate to every orientation be default (which is what I want), yet mine does not. Everything rotates perfectly in iOS 5, and I can get my splash screen to rotate perfectly in iOS 6, but that is all. I cannot get the activities (once you click through the splash screen) to rotate properly.

I have searched stackoverflow and other websites to figure out what I must do, so I know to implement -(BOOL)shouldAutorotate and -(NSUInteger)supportedInterfaceOrientations in any specific ViewController to control that view's orientation behavior. I've read that having that different rotation behavior in one VC can affect the entire app. So I made sure that every VC that I could find** would now implement those two iOS 6 methods to return YES and UIInterfaceOrientationMaskAll, respectively. That didn't work. I read about returning self.tabBarController.shouldAutorotate and self.tabBarController.supportedInterfaceOrientations in those methods to ensure that the tabbar rotation behavior is consistent, but that didn't work. I have read about implementing a category (UITabBarController+autoRotate.m and .h) that implements these two methods, and that didn't work. I have read about subclassing the tabBarController, and I think my code does that: in my appDelegate, I call

[myWindow setRootViewController:activityViewController],

where activityViewController is an instance of class BicycleFamilyAcitivityViewController, which is from

@interface BicycleFamilyActivityViewController : UIViewController <UITabBarControllerDelegate>

When I investigate what is being called during the successful splash screen rotation using the iOS 6 simulator, I notice that those two implemented methods in BicycleFamilyAcitivityViewController are being called (twice each, actually) and that -(void)willAnimateRotationToInterfaceOrientation:duration is as well. When I try to rotate while viewing an activity (after clicking through the splash screen), those two methods are only called once, and -(void)willAnimateRotationToInterfaceOrientation:duration is not called. In both instances, the appDelegate's -(NSUInteger)application:supportedInterfaceOrientationsForWindow method is called.

Any advice on how to get rotation to work throughout the entire app? Even if it's just pointing to an answer on StackOverflow that I haven't yet seen (or fully understood), I would be most grateful.

Many thanks in advance!

Bernie

** In looking for VC classes in the project, I made sure to consider any class that implemented the rotation method of iOS 5: -(BOOL)shouldAutorotateToInterfaceOrientation:interfaceOrientation

Bernie
  • 13
  • 4

2 Answers2

0

In iOS 6 the Orientation functions have changed. Your set up should look like this in your viewControllers:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}

-(BOOL)shouldAutorotate {
    return TRUE;
}

UIInterfaceOrientationMaskAll is all orientations, more information here.

John Riselvato
  • 12,854
  • 5
  • 62
  • 89
  • Thanks John, I had implemented those methods in the viewControllers, save for preferredInterfaceOrientationForPresentation. I added that method in each viewController, in case that was the difference-maker. It wasn't, though. I know that the individual viewControllers are not having shouldAutorotate & supportedInterfaceOrientations called. I think if I could get the system to make those calls, everything should fall into place (because rotation works perfectly in iOS 5). Any other suggestions? – Bernie Jun 03 '13 at 14:57
  • I would still up vote your answer, because it is a correct one; but I need a reputation of 15 to do so! – Bernie Jun 03 '13 at 15:00
  • I have not figured it out yet. The shouldAutoRotate and supportedInterfaceOrientations methods in my rootVC (BicycleFamilyActivityViewController) are called upon rotation, and they return YES and UIInterfaceOrientationMaskAll, but that doesn't seem to rotate the tabbar or anything. I can write out calls to the corresponding methods in the subViewControllers from these methods, but that doesn't help. – Bernie Jun 03 '13 at 16:33
  • check this out http://stackoverflow.com/questions/12522903/uitabbarcontroller-rotation-issues-in-ios-6 – John Riselvato Jun 03 '13 at 17:48
  • I did implement that Category, but it didn't seem to help. Unfortunately, the Category functions are not called by the system upon rotation. The function supportedInterfaceOrientations is called when a viewController loads; shouldAutorotate never seems to be called. – Bernie Jun 03 '13 at 22:10
0

Someone in-house figured out the problem. I thought I would post the answer to help anyone who has a similar predicament.

What I had tried (among other things) was: setting the UIWindow in my appDelegate class to be my instance of a subclass (BicycleFamilyAcitivityViewController) of UIViewController. In my appDelegate, I had:

[myWindow setRootViewController:activityViewController];

where activityViewController is an instance of a subclass of UIViewController.

But I should have created an additional UIWindow via delegate, then assign the TabBarController (tbc) as it's root VC when I build my TabBarController. In my primary view controller class, I had a buildTabBarController function. So these two lines in that function allowed my rotation to work:

UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow setRootViewController:tbc];

Hope this helps!

Bernie
  • 13
  • 4