cessmestreet
cessmestreet

Reputation: 2318

Supported Orientations

I saw this in another post. I get that I need to override the first method for iOS5 and the following two for iOS6.

iOS 5:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

iOS 6

- (BOOL) shouldAutorotate
{
      return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
      return UIInterfaceOrientationMaskLandscapeRight;
}

But, I do have some questions with how to use them properly.

  1. Let's say i set the supportedOrientations in the settings of my XCode project, do I have to implement shouldAutoRotate and SupportedInterfaceOrientations? What happens if I don't?
  2. If I don't override shouldAutoRotate, is the default value YES?
  3. If I return NO in shouldAutorotateToInterface, i get a warning "shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation." Is this bad? Does it have an implication in my app?
  4. When do you get the crash "Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES;"
  5. What will happen if I return NO in shouldAutorotate and I have multiple supprotedInterfaceOrientations? Is it the same as just using portrait because my VC won't be rotation?
  6. What if I return YES in shouldAutorotate, I have multiple supported orientation in my Xcode settings but I override a supportedInterfaceOrientations and return only 1?

Upvotes: 1

Views: 1231

Answers (1)

txulu
txulu

Reputation: 1792

I'm doing the vast majority of these answer by memory so there might be some errors...

  1. Those values you entered will be used for all your view controllers. You would have to override them if you wanted to specify a different behavior in one view controller.
  2. Yes. Tested it in a new project with:

    // Should autorotate not implemented
    -(void)viewDidLoad {
         [super viewDidLoad];
         NSLog(@"%@", [self shouldAutorotate]?@"y":@"n");
    }
    
  3. You get the warning because you are saying that should not autorotate but giving him more than one supported interface orientations with shouldAutorotateToInterfaceOrientation:. Either support orientations and give the possible ones or don't.
  4. If you tell your application (in the .xcodeproj) to support, for example, only portrait up and you specify in your view controller that your supported interface orientation does not include portrait up.
  5. You are telling the system not to AUTO rotate. You should be then doing the rotation manually. It's possible that the status bar will rotate but your interface won't.
  6. That screen will always be in that interface orientation, it won't rotate. The interfaces you specify in the xcodeproj are the ones that CAN be supported across the app. Then you can have specific view controllers that only support one or many of those orientations.

That said, it's usually very difficult to get the exact desired behavior. So the usual approach is 'trial & error'. Or as one of my teachers always said 'error & trial' because you are already making an error with that approach =)

Upvotes: 2

Related Questions