I have view structure like below.
HomeView(Support only portrait mode)
|
|
V
View1(Support all orientation)
|
|
V
View2(Support all orientation)
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 Cotnrollers
exists 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.