【问题标题】:Make visible ViewController inactive使可见的 ViewController 处于非活动状态
【发布时间】:2012-08-21 10:25:19
【问题描述】:

我有 UIWindow,它的 rootViewController 有蓝色背景,允许各种方向改变:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

然后我用新的 rootViewController (SecondViewController) 创建新的 UIWindow:

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

SecondViewController* secondVC = [[SecondViewController alloc] init];

window.rootViewController = secondVC;

window.windowLevel = UIWindowLevelStatusBar;
[window makeKeyAndVisible];

SecondViewController 只允许纵向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

对我来说最重要的是要像弹出窗口一样添加 SecondViewController 视图。这样用户就可以看到以前VC的背景了。

但是当我旋转设备时,它会向我的 VC 询问 - (BOOL)shouldAutoRotate... 方法,然后我进入了横向模式,并且状态栏出现在横向模式下。

理想情况下我想知道是否完全拒绝旋转(蓝色,黄色,状态栏不会旋转)。

请帮忙。

【问题讨论】:

  • 您希望达到什么目标?当用户转动设备时,您希望 SecondViewController 隐藏吗?
  • 我想拒绝改变方向

标签: ios uiviewcontroller uiinterfaceorientation uiwindow


【解决方案1】:

您可以在项目文件中设置允许的方向。

  1. 单击项目树的顶层。
  2. 点击左栏中“目标”下的目标
  3. 在“摘要”选项卡中,您可以选择“支持的设备方向”

【讨论】:

  • 我无法管理项目设置和其他视图控制器,因为它将是第三方应用程序。而且我正在开发静态库并且只能访问 SecondViewController。
  • 所以在 SecondViewController 中你需要拒绝整个应用程序的方向或者只是隐藏你的 SecondViewController?
  • 在 SecondViewController 中,您需要拒绝整个应用程序的方向,正确!
  • 在您的 SecondViewController 中,您只能控制该视图控制器。我猜你可以以某种方式破解它,但你应该考虑一下你正在尝试做的事情。如果您开发一个静态库以在其他应用程序中使用,则该静态库不应控制应用程序的行为,而是相反。
  • 是的,但我只想在我的视图控制器视图出现时拒绝改变方向
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-25
相关资源
最近更新 更多