iOS 6 UITabBarController 支持当前 UINavigationcontroller 的方向

2024-04-29

我有一个 iPhone 应用程序正在更新到 iOS 6,但存在旋转问题。我有一个UITabBarController与 16UINavigationCotrollers。大多数子视图可以纵向或横向工作,但其中一些只能纵向。在 iOS 6 中,事情在不该发生的时候发生了变化。

我尝试子类化 tabBarController 以返回supportedInterfaceOrienations当前navigationController的选定viewController:

- (NSUInteger)supportedInterfaceOrientations{

    UINavigationController *navController = (UINavigationController *)self.selectedViewController;
    return [navController.visibleViewController supportedInterfaceOrientations];
}

这让我更近了。视图控制器在可见时不会旋转离开位置,但如果我处于横向状态并切换选项卡,则新选项卡将处于横向状态,即使它不受支持。

理想情况下,应用程序将仅处于当前可见视图控制器支持的方向。有任何想法吗?


子类化你的UITabBarController重写这些方法:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

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

-(BOOL)shouldAutorotate
{
    return YES;
}

子类化你的UINavigationController重写这些方法:

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

-(BOOL)shouldAutorotate
{
    return YES;
}

然后在您不想旋转的 viewController 中实现这些方法:

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

对于您确实想要旋转的 viewController:

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

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }

    -(BOOL)shouldAutorotate
    {
        return YES;
    }

您的 tabbarController 应添加为应用程序窗口的 RootviewController。如果您计划支持默认方向(iPhone 的默认方向为除倒置外的所有方向),那么您无需执行任何其他操作。如果您想支持颠倒或不想支持其他方向,则需要在应用程序委托和/或 info.plist 中设置适当的值。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 6 UITabBarController 支持当前 UINavigationcontroller 的方向 的相关文章

随机推荐

  • 什么触发了java垃圾收集器

    我对 Java 中垃圾收集的工作原理有点困惑 我知道当不再有对某个对象的实时引用时 该对象就有资格进行垃圾回收 但是如果它有对实时对象的引用怎么办 可以说我有一个节点集合 它们再次引用更多节点 List 1 gt Node a gt Nod
  • 在轮询 SCM 时将 ssh-agent 与 jenkins 结合使用

    我使用 Jenkins ssh agent 插件来为我的构建提供 ssh 凭证 该凭证运行良好 但是我将其设置为轮询 scm 在本例中为 bitbucket git 以检查更改 当然 要访问存储库以轮询更改 它还需要这些 ssh 凭据 我似
  • ios 如何为文本字段添加底部边框和侧面设计

    我想添加底部边框 如下图所示 我已成功添加底线 但我没有得到侧面小线 这是我的代码 CALayer border CALayer layer CGFloat borderWidth 1 border borderColor UIColor
  • Swift:ViewModel 应该是结构体还是类?

    我正在尝试在我的新项目中使用 MVVM 模式 第一次 我创建了所有的视图模型来构建 但是 当我使用闭包实现异步业务逻辑 例如 fetchDataFromNetwork 时 闭包捕获旧视图模型值 然后更新为该值 不是新的视图模型值 这是操场上
  • 将订单总重量添加到 WooCommerce 新订单电子邮件通知

    是否可以在 WooCommerce 新订单 电子邮件通知 针对管理员 中显示订单的总重量 这是挂钩在 woocommerce email after order table 操作挂钩中的自定义函数 它将在 新订单 电子邮件通知中显示总重量
  • 使用 Java 重新启动 Tomcat

    我需要从 Java 代码重新启动 tomcat 例如 如果某个查询在一段时间内没有执行 那么它将自动重新启动 tomcat 我已经尝试了以下关闭和启动代码 但是当我们关闭tomcat时 java代码将不会运行并且tomcat不会启动 注意
  • 在 python matplotlib 中格式化损坏的 y 轴

    我正在 matplotlib 中处理一个 相当复杂的 条形图 它包含来自多个源的摘要数据 每个源都沿 x 轴标记 y 轴上有一系列结果 许多结果都是异常值 我尝试使用断开的 y 轴来显示这些结果 而不会使用以下组合来扭曲整个图表这个方法 h
  • 使用 Javascript OAuth 2.0 SDK 更新签名请求

    随着新的 Javascript SDK 和 OAuth 2 0 的发布 我想知道是否可以在不重定向用户的情况下更新 SignedRequest 和 authtoken 因此我使用了以下方法 基本上 这是我的应用程序的一种保持活动状态的方法
  • jquery 是否有 .toggle() 的替代方案[重复]

    这个问题在这里已经有答案了 目前根据 Jquerysite http api jquery com category deprecated deprecated 1 8 toggle 在 1 8 版本后已被弃用 那么有没有 toggle 的
  • Windows 消息

    我需要发送带有自定义 ID 的自定义 Windows 消息 其他应用程序将侦听该消息 Windows 是否为内部消息保留任何预定义的消息 ID 范围 如 SQL Server 那样 内部消息最多为 50 000 The 文档 https m
  • Mysql:磁盘已满错误

    我的 mysql 服务器有一些问题 120310 6 55 36 ERROR usr libexec mysqld Disk is full writing virtual cdrs MYD Errcode 28 Waiting for s
  • Git 责备文件中的作者列表

    有没有办法找到在 repo 中编辑 java 文件中的类的作者列表git blame 作者列表必须是唯一的 我尝试使用以下命令 但它没有删除重复项 并且每行输出中都有 作者 一词 不需要对输出进行排序 但我希望获得没有任何重复的输出 git
  • std::vector 错误 C2582:“operator =”函数在以下位置不可用

    我使用简单的向量push back到类型A的对象 并收到此错误 这是我的代码 class A public A int a int b int c include A h std vector a vec objects new std v
  • 数据映射器和连接池逻辑

    所以我尝试在 Rails 3 2 8 应用程序中使用 datamapper 我有一个config initializers dm rb我加载的地方database yml hash YAML load File new database y
  • fgets 和 fread 之间的区别

    我有以下代码 include
  • iOS - 支持 iPad 和 iPhone,无需使用笔尖

    我正在尝试编写一个应用程序而不使用nib 一切我都会以编程方式完成 现在的问题是 我该如何支持两者iPad and iPhone 显然 我不能这样做 if UIDevice currentDevice userInterfaceIdiom
  • 是否有一种仅使用极坐标来查找附近点的算法?

    假设我有一个点向量作为极坐标 假设其中一个点充当探针 我想找到一定距离内的所有其他点 是否有一种算法可以在不将它们转换为笛卡尔形式的情况下执行此操作 您正在寻找极坐标的距离 你可以在这里找到公式link http math ucsd edu
  • webpack-dev-server 中的代理 websockets 连接

    是否可以在 webpack 开发服务器中代理 websocket 连接 我知道如何将常规 HTTP 请求代理到另一个后端 但它不适用于 websockets 大概是因为代理配置中的目标以 http 开头 webpack dev server
  • 如何使用 php 将文本区域中的链接转换为链接元素?

    我正在创建一个脚本 它包含一个发布脚本 但我希望用户直接从其他任何地方复制链接 当他们发布链接文本时 链接文本应自动将链接转换为链接元素 a 例如 Ask this on http stackoverflow com now 成为 Ask
  • iOS 6 UITabBarController 支持当前 UINavigationcontroller 的方向

    我有一个 iPhone 应用程序正在更新到 iOS 6 但存在旋转问题 我有一个UITabBarController与 16UINavigationCotrollers 大多数子视图可以纵向或横向工作 但其中一些只能纵向 在 iOS 6 中