Supporting Multiple Interface but have single interface in home screen not working in iOS8 + iPhone

后端 未结 1 1073
鱼传尺愫
鱼传尺愫 2020-12-30 11:37

I have view structure like below.

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


        
相关标签:
1条回答
  • 2020-12-30 12:10

    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.

    0 讨论(0)
提交回复
热议问题