8
votes

I have view structure like below.

HomeView(Support only portrait mode)
 |
 |
 V
View1(Support all orientation)
 |
 |
 V
View2(Support all orientation)

Problem :
When i am coming back from View2(Landscape mode) to HomeView by calling popToRootViewController method,It did not call supportedInterfaceOrientationsForWindow method of App_Delegate and display HomeView in landscape mode.

Image:

enter image description here

Note :
Same thing not happens when i came back from View1(Landscape mode) to HomeView by calling popToRootViewController method it will call supportedInterfaceOrientationsForWindow and all works great.
If I run app using XCode6 in iOS7 all works great.

I read below question but it did not help me.
How to maintain presenting view controller's orientation when dismissing modal view controller?

In above link matt said that iOS8 stop support for friezing orientation, but I did not find it in apple document if you have any reference link about this change please share.

Question :
1] Why delegate method supportedInterfaceOrientationsForWindow is not calling.
2] Is it possible to have one view with support single orientation and all other will support all orientation.

Thanks

1

1 Answers

3
votes

I solve it and post answer as it will may help some one

Problem :
I have below code in supportedInterfaceOrientationsForWindow.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    // Suport only portrait mode for home screen
    if([self.navigationController.topViewController isKindOfClass:[ViewHome class]])

    {
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskAll;
}

But delegate method supportedInterfaceOrientationsForWindow not called when use popToRootViewControllerAnimated method when there ismore then two view Cotnrollersexists in stack.

Solution :
Step1: Create sub class of Navigation controller.

Step2: Override method popToRootViewControllerAnimated and write code as below // Overwrite super class method popToRootViewControllerAnimated.

-(NSArray*)popToRootViewControllerAnimated:(BOOL)animated
{
    // Only for iOS8 and above
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
    {
        // Array which will contaimn all poped view controllers object.
        NSMutableArray *popedControllersArray = [[NSMutableArray alloc] init];

        // Tmp created controllers object
        NSArray *controllers;

        // Hold first view cotnrollers.
        UIViewController *firstViewController = [self.viewControllers objectAtIndex:1];

        // Pop to first view controllers with no animation.
        controllers = [super popToViewController:firstViewController animated:NO];

        // Add poped view cotnrollers objects to the array.
        [popedControllersArray addObjectsFromArray:controllers];

        // Pop to root view controller with animation
        [super popViewControllerAnimated:YES];

        // Add first view controller object as it is poped by above line.
        [popedControllersArray addObject:firstViewController];

        // return poped view controllers object.
        return popedControllersArray;
    }
    else
    {
        // Called super view popToRootViewControllerAnimated method and return popped
        // view controllers array.
        return [super popToRootViewControllerAnimated:animated];
    }
}


Please fill free for any comments and ask for any questions.