Ios 6 navigation controller tablet controller

I am currently working on a project in which we have a tab bar controller with 4 tabs and where each tab has a navigation controller. On each of these navigation controllers, several controllers are pressed on it.

I read a lot of posts here and other places, and we currently do the following:

Subclass UITabbarcontroller

- (BOOL)shouldAutorotate { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotate]; } - (NSUInteger) supportedInterfaceOrientations { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController]supportedInterfaceOrientations]; } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } 

This work is great if we specify the following in each of our view controllers:

 - (NSUInteger) supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return YES; } 

This will block it until Portrait, as expected.

But now a real problem arises! If in our view the dispatcher on one of the tabs indicates that it should rotate into the landscape, it works fine, but when we change the tab, it is still in the landscape, which we don’t want!

So, to summarize, does anyone have a solution, how do you block almost all views on a given orientation, and can change the tabs where they are in the orientation you specified (here is a portrait)?

I also read this post. IOS 6 UITabBarController supported orientation with the current UINavigation controller , but as one comment noted, “it almost works for me. I am already in the landscape when I switch tabs to portrait only because it is still located in the landscape. A rotating portrait captures it and it won’t turn back to the landscape, but I still need it to be in the portrait when it first loads up ", which is almost the same here ..

+2
source share
1 answer

I had this problem and I developed a solution, it is not very, but it works.

Your TabbarController subclass implements the tabbarcontroller delegate function (don't forget to set the delegate):

 -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ int selected = self.selectedIndex; UIViewController *con = [[UIViewController alloc] initWithNibName:@"XIBName" bundle:nil]; [[self.viewControllers objectAtIndex:selected] pushViewController:con animated:NO]; [[self.viewControllers objectAtIndex:selected]popViewControllerAnimated:NO]; [[self.viewControllers objectAtIndex:selected] setDelegate:nil]; } 

Pressing and pop in the uinavigation controller in the tabs navigation manager will cause the tabbarcontroller to run its Orientations functions again, and if you correctly executed the orientation code, it will change to the desired orientation.

Hope this helps, please feel free to comment if I need to explain anything in detail.

Regards Morten

+2
source

Source: https://habr.com/ru/post/1443428/


All Articles