Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 Rotation: Pushing a View Controller

I want to support iOS 6 rotation. Trouble is, I've been looking through a lot of documentation and stack overflow questions but have not found any even slightly in depth solutions. I've only seen that I should add these two methods to my view controller classes - however, if I'm not mistaken, they do not operate in the same way as the pre iOS 6 methods:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll; // use what is appropriate for you.
}

My app currently rotates in pre-iOS6 using the following code. Note that I use the interface orientation parameters to determine whether or not I'm going to push my view Controller. How do I implement this in the iOS 6 rotation delegates?

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    UIInterfaceOrientation toOrientation = self.interfaceOrientation;

    if ( self.tabBarController.view.subviews.count >= 2 )
    {
        UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];

        if(toOrientation != UIInterfaceOrientationLandscapeLeft && toOrientation != UIInterfaceOrientationLandscapeRight)
        {
            CUSTOM_DEBUG_LOG("\n\nRotated back to Portrait");
            tabBar.hidden = FALSE;
        }
    }
}

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        CUSTOM_DEBUG_LOG("\nView going landscape");
        ScrollViewController *s = [[ScrollViewController alloc] initWithNibName:@"ScrollViewController" bundle:nil];
        [self.navigationController pushViewController:s animated:NO];
        [s release];
        self.tabBarController.tabBar.hidden = YES;
        self.navigationController.navigationBar.hidden = YES;
    }

}
like image 485
Mark S Avatar asked Oct 04 '12 18:10

Mark S


2 Answers

Checkout this and this SO discussion.

[EDIT]

Yes the methods you mentioned aren't deprecated in iOS 6.0 and they will continue working. It's just the way Auto Rotation works have been changed. So far it was view controllers responsibility to decide whether they rotate or not but now RootViewController will decide whether their children should rotate or not. If you don't have rootviewcontroller setup then you have to add it to window and then put shouldAutoRotate and supportedInterfaceOrientations methods in the rootviewcontroller.

like image 53
AlienMonkeyCoder Avatar answered Oct 17 '22 05:10

AlienMonkeyCoder


Parent Views now handle rotation in iOS 6. Subclass your nav controllers and add a bool

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;  // your rotation here
}
like image 3
JSA986 Avatar answered Oct 17 '22 05:10

JSA986