【问题标题】:iOS: request for up to date solution for UITabBarController rotationiOS:请求 UITabBarController 旋转的最新解决方案
【发布时间】:2011-06-09 10:37:01
【问题描述】:

在处理 UITabBarController 时,旋转内部视图的最新最佳解决方案是什么?我正在使用标准的应用程序视图层次结构:在我的主应用程序委托文件中,我正在创建 UITabBarController,然后,我正在创建 UINavigationController,用 UITableViewController(带有实例化的自定义子类)填充它,并将 UINavigationController 添加到第一个标签栏项目。现在,我需要 UITableViewController 来自动旋转。我知道我需要在所有视图控制器中实现 shouldAutorotateToInterfaceOrientation,因此,我在我的自定义 UITableViewController 子类实现文件中实现了它:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
  return YES; 
}

但是 UITableViewController 没有旋转 :( 。现在,我知道有 UINavigationController 和 UITabBarController 对象,它们位于我的 TVC 上方,但是这两个是直接实例化的,而不是通过子类,所以没有地方可以返回 yes用于自动旋转。但是,我可以通过子类化 UITabBarController 并在其实现文件中实现 shouldAutorotateToInterfaceOrientation 方法来解决这个问题。但我读过,这是一种不推荐的方法,我的良心感觉很糟糕:) 另一个可行的解决方案是为 UITabBarController 实现一个类别 (http://stackoverflow.com/questions/1269704/uitabbarcontroller-morenavigationcontroller-and-the-holy-grail-of-device-rotatio)...

所以,这两个解决方案是我能够应用的唯一解决方案。是否有任何其他“开箱即用”的解决方案,例如,在 UITabBarController 或 smth 上设置一些属性?

【问题讨论】:

    标签: iphone objective-c ios uitabbarcontroller rotation


    【解决方案1】:

    在您继承 UITableViewController 或在 UIViewController 中实现 UITableView 的类中,您需要为 tableView 设置 autoresizingMask。有点像

    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    并且 TableView 应该可以正常旋转。

    希望有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 2011-10-15
      相关资源
      最近更新 更多