0
votes

I have parent view controller and another modal view controller. I presented modal view controller within parent's context:

readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:reading_view_controller animated:YES];

Parent viewController will not orient Landscape; so, i added these methods in the parent viewController:

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


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

The presented viewController (modally presented) should orient to all possible orientations; so, i added these methods:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{

    return YES;
}

But, because I assumed (UIModalPresentationCurrentContext), the presented viewController doesn't orient in IOS 6.0 while it is working as expected in IOS 5.0

How to solve this problem please?

2

2 Answers

1
votes

If you have a tab-based app, then first add some code in app delegate and also self.window.rootviewcontroller-self.tabbarcontroller.

        @implementation UITabBarController (SK8FASTR2App)
        -(BOOL)shouldAutorotate
        {
            return YES;
        }

        - (NSUInteger)supportedInterfaceOrientations
        {
            // your custom logic for rotation of selected tab
             if (self.selectedIndex==3){
             return UIInterfaceOrientationMaskPortrait;
             }
             else {
            UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight;
             return UIInterfaceOrientationMaskAll;
             }

        }

        @end



        before

        @implementation AppDelegate


    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
            return  UIInterfaceOrientationMaskAll;
    }

Change orientation on that class

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}
0
votes

You should implement

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

eg :-

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}