2

I developed IOS 5 application using game center. Now I want my code to run on IOS 6. So I have let my application to support both orientation i.e landscape and portrait so that it does not crashes when game center login screen pops up. But after that, my home view controller does not starts in landscape view. Instead when I go to a further view, it opens in landscape, and then when i come back, then the home view opens in landscape. But home view does not opens to landscape mode for the first time.

Here is the code :

- (BOOL)shouldAutorotate
{
  return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

These are the delegates I use in home view for IOS 6.

NiKKi
  • 3,296
  • 3
  • 29
  • 39
  • Have u supported all orientations in projects plist file? – AppleDelegate Sep 26 '12 at 11:36
  • @AppleDelegate - Supported just the two landscape orientations.. – NiKKi Sep 26 '12 at 13:55
  • Is your homeViewController the root view controller of a UINavigationController? – rocky Sep 26 '12 at 20:52
  • 1
    Thnx @rocky . Your comment reminded me that I have added the homeViewController as a subView instead of making it rootViewController. Now I have made homeViewController , rootViewController and now it works fine. Thanks. – NiKKi Sep 27 '12 at 06:28

1 Answers1

5

Add this method in your app delegate to support desired orientation for IOS 6..

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
}

and use these delagates for orientation in rest of clases for IOS 6.

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}
NiKKi
  • 3,296
  • 3
  • 29
  • 39
  • Could you explain what the first bit of code is supposed to do and a bit more specific cases of "classes for IOS 6" for the second? I'm suspecting you mean "views", but haven't tried it yet. – Danny Oct 09 '13 at 20:37