gpt4 book ai didi

iphone - 导航 Controller 应用程序中 2 个 UIViewcontroller 的方向问题

转载 作者:行者123 更新时间:2023-12-01 19:20:11 25 4
gpt4 key购买 nike

我有一个标签栏应用程序。第一个选项卡的项目是导航 Controller 。
导航 Controller 的堆栈中有 4 个项目。
我想提供轮换。但是在标签栏应用程序中,这是问题所在,这就是我创建自己的标签栏 Controller 并覆盖该方法的原因:

@interface RotatingTabBarController : UITabBarController

@end

@implementation RotatingTabBarController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
BOOL f = [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
} else {
BOOL f = [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
}
}

@end

之后,如果我提供适当的 UIInterfaceOrientation 支持,我的 Controller 将支持自动旋转。但是没有我的自定义 RotatingTabBarController 这似乎是不可能的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

问题是:
当我在此 View Controller 的 shouldAutorotateToInterfaceOrientation 中将 FirstViewController 插入导航 Controller 时,我只提供纵向,
但是当我按下 SecondViewController(我提供纵向和横向方向)时,如果 SecondViewController 的当前界面方向是横向并且我按下返回按钮(从堆栈中弹出 SecondViewController 并且出现 FirstViewController),则 FirstViewController 的方向是横向的。但在 shouldAutorotateToInterfaceOrientation 方法中,我只为他提供纵向方向。

最佳答案

实际上你不应该继承一个 UITabbarController 类。

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This class is not intended for subclassing.



来自 UITabBarController Class Reference

如果您查看 Controller 覆盖
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

方法,应该没问题。

我认为支持某些 View 横向和某些不在应用程序中的 View 不是一个好主意。

你已经找到了原因,如果用户在横向模式下按下返回按钮怎么办?

这里应该做什么,当设备具有横向方向时旋转到纵向?

如果你想这样做,没有简单的方法可以强制设备改变方向。您必须使用转换来处理您自己的 View 方向。

您可以使用不在导航 Controller 堆栈上的 Model View Controller 支持 View 的不同方向。

关于iphone - 导航 Controller 应用程序中 2 个 UIViewcontroller 的方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10756077/

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