gpt4 book ai didi

iPhone iOS 6 UITabBarController 仅纵向,如何让模态视图 Controller 支持横向

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:25 25 4
gpt4 key购买 nike

我想做的是最简单的概念。但是,我只是没有得到任何想要的结果。

我的应用是一个标准的标签栏应用,每个标签中的所有 View Controller 都只支持纵向,这正是我想要的。

但是,在应用程序的一个部分中,我显示了一个模态视图 Controller ,它显然覆盖了选项卡栏 Controller 。这是一个文本输入屏幕,我非常希望这个 View 能够支持横向和纵向。然后,一旦用户取消了该模态视图 Controller ,标签栏 Controller 将再次显示,所有内容都是纵向的。

我尝试了很多方法,但没有任何效果。如果我告诉应用程序支持两个方向,那么旋转会在模态上正确发生,但也会在应用程序的其余部分发生,这是我不想要的。

我已经尝试实现所有新的 shouldAutorotate 和 supportInterfaceOrientations 方法,但似乎没有任何效果。

我必须做的最接近工作的尝试是,我在我的应用委托(delegate)中创建了一个 UITabBarController 类别,以转发 shouldAutorotate 和 supportedInterfaceOrientations。这似乎最初有效,但出于某种原因,每当取消我的模态 vc 时,我的应用程序的标签栏部分总是在状态栏后面向上移动 20 像素?我不知道这是怎么回事。

我创建了一个测试应用程序,其中没有 UITabBarController,我能够毫无问题地编写我想要的行为,而且它运行良好。因此,很明显,与 Tab Bar Controller 相关的某些事情使这个问题变得棘手。

请告诉我解决这个简单概念的诀窍是什么。

谢谢!

最佳答案

我能够通过为 UITabBarController 和 UINavigationController 创建几个类别来解决这个问题。这是我使用的代码:

@implementation UITabBarController (rotations)

- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}

@end

@implementation UINavigationController (navrotations)

- (BOOL)shouldAutorotate {

return [self.topViewController shouldAutorotate];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}

@end

当然,我显示的每个 View Controller 都需要响应 shouldAutorotate 和 supportedInterfaceOrientations 方法。

关于iPhone iOS 6 UITabBarController 仅纵向,如何让模态视图 Controller 支持横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13765544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com