0
votes

Last time I ran an iOS app I made, it must have been on for deployment target 5.0 and the associated SDK (there's a chance it could have been as early as 4.3). The deployment is now 6.1. My app only runs landscape and worked fine in landscape. But after I updated my iPad and iOS SDK and ran this app for the first time in about a year, it seems something has changed.

The buttons show up as if the iPad is in portrait mode. This is wrong, because it should be in landscape (and it used to work just fine).

What has changed in the newest updates?

My supported interface orientations in Xcode have "Landscape Right" selected only and in the Info section I have "Supported interface orientations" with just a single Item: "Landscape (right home button)".

In my main view control that opens when the app first opens, I have

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

and also the first line of the viewDidLoad is

self.view.frame = CGRectMake(0, 0, 1024, 768);

So why is the code drawing buttons as if it is in Portrait mode?


UPDATE

I have tried to replace the shouldAutorotateToInterfaceOrientation method with

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationLandscapeRight & UIInterfaceOrientationLandscapeLeft;
}

but it still doesn't work.

2
so, now deployment target is iOS 6.1? - jamapag
shouldAutorotateToInterfaceOrientation deprecated in iOS 6. - jamapag
Oh...so what should I do to fix this? - CodeGuy
You don't want to use & in supportedInterfaceOrientations, as that will return false. Use || instead. - thegrinner

2 Answers

0
votes

Orientation changes in iOS6.0

You should implement the following methods

-(BOOL)shouldAutorotate
{
  return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscape;
}

// Set the initial preferred orientation
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return   UIInterfaceOrientationLandscapeRight;
}

Note
If you are using TabBarController/NavigationController you should sub class those view controller to override the orientation methods in such a way that it should call your own view controller methods. This is a significant change in iOS6.

 #import "UINavigationController+Orientation.h"

@implementation UINavigationController (Orientation)

-(NSUInteger)supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
 {
   return YES;
 }

 @end
0
votes

shouldAutorotateToInterfaceOrientation is deprecated in iOS 6, you should override supportedInterfaceOrientations method of UIViewController

There is quote from doc:

In iOS 6, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Generally, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate in directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.

You can override the preferredInterfaceOrientationForPresentation for a view controller that is intended to be presented full screen in a specific orientation.