更改选项卡时忽略自动旋转

发布于 2024-10-22 07:51:06 字数 495 浏览 7 评论 0原文

我有一个带有 UITabBarController 的应用程序,每个选项卡都有一个“附加”到它的 UINavigationController 。现在让我们假设选项卡 1,2 和 4 中的 rootViewControllers(导航控制器)仅支持纵向方向,并且具有这样的“shouldAutorotateToInterfaceOrientation”实现,仅在要求旋转到纵向时返回 YES。然而,选项卡 3 的 navigationController 中有一些支持横向的 viewController。

当我现在处于选项卡 3 并移动到支持横向的视图控制器之一时,我可以将设备和界面更改为横向。然而,如果我在界面处于横向模式下点击选项卡 1,2 或 4,界面不会变回纵向,而是保持横向,尽管显示的 viewController 显然只支持纵向。

我不确定我缺少什么或者这是否是预期的行为,一旦我通过 tabBarController 切换到仅纵向视图控制器,我希望界面方向切换回纵向。整个层次结构是以编程方式构建的。

谢谢!

I have an application with a UITabBarController, each of the tabs has a UINavigationController "attached" to it. Now lets assume that the rootViewControllers (of the navigationControllers) in Tabs 1,2 and 4 only support the portrait orientation and have such a "shouldAutorotateToInterfaceOrientation" implementation that only returns YES when asked to rotate to portrait. Tab 3 however has some viewControllers in its navigationController that support landscape orientation.

When I am in tab 3 now and move to one of the viewControllers that support landscape I am able to turn the device and the interface changes to landscape. Yet if I hit tab 1,2 or 4 with the interface in landscape mode, the interface does not get changed back to portrait but stays in landscape, despite the fact that the displayed viewControllers clearly only support portrait.

I am unsure as to what I am missing or whether this is intended behavior, I would like the interface orientation to switch back to portrait once I switch to a portrait only viewController via the tabBarController. The entire hierarchy is constructed programmatically.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的心爱 2024-10-29 07:51:06

我在我的一个应用程序上遇到了与您相同的问题,不同之处在于我没有在选项卡项中使用导航控制器。

我最终为 UITabBarController 创建了一个类别(因为它不应该被子类化),用于方法 shouldAutorotate...

@implementation UITabBarController (orientation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
#if DEBUG 
    NSLog(@"UITabBarController (orientation) -> shouldAutorotateToInterfaceOrientation: [%d]",toInterfaceOrientation);
#endif  
    //if(toInterfaceOrientation == UIInterfaceOrientationPortrait) return YES;
//  else return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    if (self.selectedViewController == [self.viewControllers objectAtIndex:kLibraryStoreTabIndex])
        return NO;


    if( self.selectedViewController == [self.viewControllers objectAtIndex:kContactTabIndex]){

        return YES;
    }
// rest of the conditions depending of the tab 

return NO; //last option 
}

I was having the same issue as you on one of my apps, with the difference that I was not using navigation controllers in the tab items.

I ended up creating a category for the UITabBarController (since it's not meant to be subclassed) for the method shouldAutorotate...

@implementation UITabBarController (orientation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
#if DEBUG 
    NSLog(@"UITabBarController (orientation) -> shouldAutorotateToInterfaceOrientation: [%d]",toInterfaceOrientation);
#endif  
    //if(toInterfaceOrientation == UIInterfaceOrientationPortrait) return YES;
//  else return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    if (self.selectedViewController == [self.viewControllers objectAtIndex:kLibraryStoreTabIndex])
        return NO;


    if( self.selectedViewController == [self.viewControllers objectAtIndex:kContactTabIndex]){

        return YES;
    }
// rest of the conditions depending of the tab 

return NO; //last option 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文