UITabBarController中的UIViewController和UISplitViewController shouldAutorotateToInterfaceOrientation [英] UIViewController and UISplitViewController in UITabBarController shouldAutorotateToInterfaceOrientation

查看:152
本文介绍了UITabBarController中的UIViewController和UISplitViewController shouldAutorotateToInterfaceOrientation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPad代码存在一些问题。

i have some Problems with my iPad Code.

我有一个UITabBarController,它包含一些UIViewController和一个UISplitViewController。问题是UIViewController甚至UISplitViewController都没有正确识别方向更改。

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.

我在我的TabBarController和所有UIViewControllers上设置了shouldAutorotateToInterfaceOrientation但我意识到只有顶部的willRotateToInterfaceOrientation moast ViewController将触发哪个是我的TabBarController。如果我从我的TabBarController中删除shouldAutorotateToInterfaceOrientation将调用来自我的子UIViewControllers的willRotateToInterfaceOrientation。最大的问题是我的UISplitViewController,因为它将旋转到新的interfaceOrientation但它被粘贴在他的Portrait Layout中。

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.

如何使用ViewControllers和Splitviews正确实现TabBarController包括方向变化?

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

推荐答案

嘿,我现在想出了一个解决方法。
重新回答问题只有第一个addet View to the Window才能识别Orientation Changes。

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并使其旋转到接口方向

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
    }
}

但是现在我的TabBarController的viewControllers仍然无法识别我的InterfaceOrientations。所以我想出了以下内容:

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];
    }
}

这将从所有子类调用didRotateFromInterfaceOrientation方法TabBarController:

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
    }
}

正如你可以看到我在我的Sub Viewcontroller中调用 [self adjustViewsForOrientation:self.interfaceOrientation]; ,它将为adjust方法提供实际方向。如果你使用fromInterfaceOrientation它将是错误的Orientation,因为更改已经完成!

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!

我的另一个问题是TabBarController中的UISplitviewController,但是我想让它工作在一个可接受的方式问题与UIViewControllers相同。它不会重新定位Orientation Changes,因此你必须对其进行Subclass,但我希望它能达到100%。当我在网上搜索时,我找到了一个很好的代码示例,用于一个cutom构建Splitview。所以你可以试一试:
http:// blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait
http://www.trustedones.com/apps/ipad

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

它还使SplitView处于纵向模式,因此您可能会喜欢它。我愿意!

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

希望我可以帮助有这个帖子的人..
干杯
nettz

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

这篇关于UITabBarController中的UIViewController和UISplitViewController shouldAutorotateToInterfaceOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆