views:

658

answers:

2

Hello Guys, i have some Problems with my iPad Code.

I have a UITabBarController which holds some UIViewController and a UISplitViewController. The problem is that the UIViewController and even the UISplitViewController dont recognize orientation Changes correctly.

i have set shouldAutorotateToInterfaceOrientation on my TabBarController and all UIViewControllers but i realized that only willRotateToInterfaceOrientation in the Top moast ViewController will fire which is my TabBarController. If i remove shouldAutorotateToInterfaceOrientation from my TabBarController willRotateToInterfaceOrientation from my sub UIViewControllers will get called. The biggest problem is my UISplitViewController, because it will rotate to the new interfaceOrientation but it is stucked in his Portrait Layout.

How do i correctly implement a TabBarController with ViewControllers and Splitviews including orientation changes?

A: 

Hey i came up with a Workaround myself now. To Recap the Problem Only the first addet View to the Window will recognize Orientation Changes.

I Subclassed My TabBarController and made it ro Rotate to the Interface Orientation

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self adjustViewsForOrientation:toInterfaceOrientation];    
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Landscape");
        //Do Your Landscape Changes here


    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Portrait");
        //Do Your Portrait Changes here
    }
}

But now the "viewControllers" of my TabBarController wont still recognize my InterfaceOrientations. So i came up with The folowing:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    for (int i = 0; i < [self.viewControllers count]; i++ ) {
        [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

This will call the didRotateFromInterfaceOrientation Method from all Subclasses of the TabBarController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self adjustViewsForOrientation:self.interfaceOrientation];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Subview Landscape");
        //Do Your Landscape Changes here
    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Subview Portrait");
        //Do Your Portrait Changes here
    }
}

As You can see i call [self adjustViewsForOrientation:self.interfaceOrientation]; in my Sub Viewcontroller which will give the actuall Orientation to the adjust method. If you use fromInterfaceOrientation it will be the wrong Orientation, because the change was already done!

My other problem was the UISplitviewController in TabBarController, but i dident got it working in a acceptable way. The problem is the same as for the UIViewControllers. It wont regocnize Orientation Changes so you have to Subclass it, but i dident get it working to 100%. As i searched the Web i found a good Code Example for a cutsom build Splitview. So ull maybe give it a shot: http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait http://www.trustedones.com/apps/ipad

It also keeps the SplitView in Portrait Mode so you maybe will like it. I do!

Hope i could help someone with this post.. Cheers nettz

nettz
Did you ever figure out how to get this working exactly as you wanted?
LucasTizma
A: 

Note that the second sentence of the UITabBarController class reference states "This class is not intended for subclassing."

So, while this approach may work, I suspect it is not the "correct" one. (I too am having this problem.)

tomwhipple