2
votes

i just create a new single view application,and write three funcs in ViewController.m file.

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

First Question

I expect the Simulator rotate my view,but the view orientation is Portrait. And I find the third func not called in ViewController. why?

Second Question

I read some blogs , they said if shouldAutorotate return NO, the func supportedInterfaceOrientations will not called,but in my test, this func called several times,why?

1

1 Answers

1
votes

You have to use a UINavigationController subclass (not sure your using navigation in your project...) and implement those methods in the subclass. Do not forget to set your subclass as view-controller navigation controller Example for navigation controller subclass:

// add this in your CustomNavigationController.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController <UINavigationControllerDelegate>

@end

// add this in your : CustomNavigationController.m file

#import "CustomNavigationController.h"

@interface CustomNavigationController ()

@end

@implementation CustomNavigationController 

- (BOOL)shouldAutorotate {
    return [self.visibleViewController shouldAutorotate];
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.visibleViewController preferredInterfaceOrientationForPresentation];
}

@end