Rotation behaving differently on iOS6

后端 未结 12 2196
野的像风
野的像风 2020-11-30 06:00

I did an App which is tab-based. Nothing needs to be on landscape mode but a couple of views. It worked OK on iOS5 and I was pretty happy with the result. However with iOS6

相关标签:
12条回答
  • 2020-11-30 06:33

    This is what works for me.

    I created a new subclass of UINavigationController, and added shouldAutorotate and supportedInterfaceOrientation methods:

    #import "MyNavigationController.h"
    
    @interface MyNavigationController ()
    
    @end
    
    @implementation MyNavigationController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (BOOL)shouldAutorotate {
        return [self.visibleViewController shouldAutorotate];
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return [self.visibleViewController supportedInterfaceOrientations];
    }
    
    @end
    

    Then add this to your delegate

    UINavigationController *nvc = [[MyNavigationController alloc] initWithRootViewController:_viewController];
    nvc.navigationBarHidden = NO; // YES if you want to hide the navigationBar
    self.window.rootViewController = nvc;
    [_window addSubview:nvc.view];
    [_window makeKeyAndVisible];
    

    Now you can add this to the views you want to rotate in all orientations

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    

    Or add this to the views you only want to go portrait and portraitUpsideDown

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return
        (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown ;
    }
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    0 讨论(0)
  • 2020-11-30 06:34

    Are you setting the rootViewController in the delegate? For example,

        self.window.rootViewController = self.navigationController;
    

    When I was doing some iOS6 testing it wouldn't work properly until I did that...

    0 讨论(0)
  • 2020-11-30 06:35

    For app "Same Picture" on iOS6 I need an orientation change, my UIViewController never be informed for orientation, it's an photo overlay likely didrotate works well :

    - (void)didRotate: ( NSNotification* )note
    {
        [self performSelector:@selector(rotateRecalculDiffere) withObject:nil afterDelay:0.3 ];
    }
    

    I make fine size adjust with delayed call. From notification it's easy to know final orientation

    0 讨论(0)
  • 2020-11-30 06:42

    You might double check Support Interface Orientations

    enter image description here

    On previous version, it means nothing, but affects whole application now.

    Note: The 'upside down' option doesn't work even enabled or disabled on iOS 6.

    0 讨论(0)
  • 2020-11-30 06:43

    I have a good solution for cross 5.0 to 6.0 working - All of the above with

    -(BOOL)shouldAutorotate{return [self shouldIRotateAnyiOS];}//iOS6
    
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return [self shouldIRotateAnyiOS];}//pre iOS6
    
    -(BOOL)shouldIRotateAnyiOS{
    UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    //do the rotation stuff
    return YES
    }
    
    0 讨论(0)
  • 2020-11-30 06:43

    This code common for ios5 and ios6

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
        if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
            [self performSelector:@selector(setframeLandscap) withObject:nil afterDelay:0.2];
        }
        else {
            [self performSelector:@selector(setframePortrait) withObject:nil afterDelay:0.2];
        }
    }
    
    -(BOOL)shouldAutorotate {    
        return YES;
    }
    
    0 讨论(0)
提交回复
热议问题