UIViewController and UISplitViewController in UITabBarController shouldAutorotateToInterfaceOrientation

老子叫甜甜 提交于 2019-12-04 14:15:42

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

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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!