UITabBarController 中的 UIViewController 和 UISplitViewController shouldAutorotateToInterfaceOrientation

2024-02-03

我的 iPad 代码有一些问题。

我有一个 UITabBarController,其中包含一些 UIViewController 和 UISplitViewController。问题是 UIViewController 甚至 UISplitViewController 无法正确识别方向更改。

我已经在我的TabBarController和所有UIViewController上设置了shouldAutorotateToInterfaceOrientation,但我意识到只有Top moast ViewController中的willRotateToInterfaceOrientation才会触发我的TabBarController。如果我从我的 TabBarController 中删除 shouldAutorotateToInterfaceOrientation,将会调用我的子 UIViewControllers 中的 willRotateToInterfaceOrientation 。最大的问题是我的UISplitViewController,因为它会旋转到新的interfaceOrientation,但它卡在他的Portrait Layout中。

如何正确实现带有 ViewController 和 Splitview 的 TabBarController(包括方向更改)?


嘿,我现在自己想出了一个解决方法。 回顾一下问题 只有窗口的第一个附加视图才能识别方向更改。

我对 TabBarController 进行子类化并使其旋转到界面方向

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self adjustViewsForOrientation:toInterfaceOrientation];    
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Landscape");
        //Do Your Landscape Changes here


    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Portrait");
        //Do Your Portrait Changes here
    }
}

但现在我的 TabBarController 的“viewControllers”仍然无法识别我的 InterfaceOrientations。所以我想出了以下内容:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    for (int i = 0; i < [self.viewControllers count]; i++ ) {
        [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

这将从 TabBarController 的所有子类中调用 didRotateFromInterfaceOrientation 方法:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self adjustViewsForOrientation:self.interfaceOrientation];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Subview Landscape");
        //Do Your Landscape Changes here
    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Subview Portrait");
        //Do Your Portrait Changes here
    }
}

如你所见,我打电话[self adjustViewsForOrientation:self.interfaceOrientation];在我的子视图控制器中,它将为调整方法提供实际的方向。如果您使用InterfaceOrientation,它将是错误的方向,因为更改已经完成!

我的另一个问题是 TabBarController 中的 UISplitviewController,但我没有让它以可接受的方式工作。问题与 UIViewController 相同。它不会重新识别方向变化,所以你必须对它进行子类化,但我没有让它工作到 100%。当我在网上搜索时,我发现了一个关于 cutsom 构建 Splitview 的很好的代码示例。所以我们也许会尝试一下:http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait http://www.trustedones.com/apps/ipad http://www.trustedones.com/apps/ipad

它还将分屏视图保持在纵向模式,因此您可能会喜欢它。我愿意!

希望我可以帮助某人完成这篇文章.. 干杯 内茨

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

UITabBarController 中的 UIViewController 和 UISplitViewController shouldAutorotateToInterfaceOrientation 的相关文章

随机推荐

  • 在 Woocommerce 中添加新的自定义默认订购目录选项

    我正在尝试让 Woocommerce 的默认订单按 SKU 排序 我更改了 woocommerce 设置中的顺序并添加了 SKU 如下所示 function sv add sku sorting args orderby value iss
  • 我如何修补/模拟logging.getlogger()

    我有我想测试的代码 log logging getLogger name class A object def init self log debug Init 但我不知道如何断言 log debug 是用 Init 调用的 我尝试修补记录
  • 如何强制XPath使用UTF8?

    我有一个 XHTML 文档通过 Greasemonkey AJAX 传递到 PHP 应用程序 PHP 应用程序使用 UTF8 如果我将 POST 内容直接输出到 AJAX 接收 div 中的文本区域 则所有内容仍然以 UTF8 正确编码 当
  • 为什么广度优先搜索比深度优先搜索使用更多的内存?

    我在网上找不到这个问题的答案 在类似问题的其他答案中 似乎 DFS 的优点是它使用的内存比 DFS 少 对我来说 这似乎与我的预期相反 BFS 只需存储它访问的最后一个节点 例如 如果我们在下面的树中搜索数字 7 它将搜索值为 8 的节点
  • 在窗口内打印,而不是在边框上打印

    我试图在诅咒窗口内写一些东西 但它似乎也在边框上写 我该如何修复下面的代码 win self newwin LINES 2 COLS 0 0 box win self 0 0 wrefresh win self wprintw win se
  • Puppeteer 错误:导航失败,因为浏览器已断开连接

    我在 Google App Engine 上使用 puppeteer 和 Node JS 每当我在应用程序引擎上运行 puppeteer 时 我都会遇到一条错误消息 导航失败 因为浏览器已断开连接 这在本地环境中工作正常 所以我猜测这是应用
  • 根据列值拆分数据并创建散点图。

    我需要绘制散点图days vs age对于 f 组 性别 1 并绘制另一个散点图days vs age对于 m 组 性别 2 使用 R days age sex 306 74 1 455 67 2 1000 55 1 505 65 1 39
  • sqlite 查询子句中需要括号

    我正在运行以下 sqlite3 查询 并注意到前两个查询没有给出预期的答案 即 1240969 1225691 1531026 如果我在 or 子句周围使用括号 我会得到预期的结果 为什么是这样 sqlite gt select count
  • 根据与 R 中的字符串共享的值将颜色分配给数据框

    我在 R 中工作 我有许多不同的数据框 其中包含样本名称 我尝试根据样本名称为每个数据框中的每一行分配颜色 有许多行具有相同的样本名称 但我的输出数据很混乱 因此无法按样本名称排序 这是我所拥有的一个小例子 names lt c TC3 1
  • 如何减小 Android 中使用 FFMPEG 的默认摄像头捕获的视频大小?

    我正在尝试减小 Android 中默认摄像头 它正在生成高分辨率视频 捕获的视频大小 做FFMPEG有一个属性可以对给定分辨率的视频进行编码吗 我尝试谷歌 但所有示例都使用 FFMPEG 的命令行模式 我的问题是 我们可以在Android中
  • 获取每周的最后一个值以及匹配的日期

    所以我从pd Series called jpm 我想将其分组为几周 并取每周的最后一个值 这适用于下面的代码 它确实获得了最后一个值 但它将相应的索引更改为一周中的星期日 我希望它保持不变 import pandas datareader
  • 如何使用REUSE_ALV_FIELDCATALOG_MERGE功能模块?

    我正在尝试使用功能模块REUSE ALV FIELDCATALOG MERGE传递 ddic 中的字段标签以显示在 alv 报告的列标题中 但是 那没有用 如果我评论I STRUCTURE NAME TY YNAH CUS OBJ REQ
  • 使用 javascript 在 html 页面中查找单词

    如何快速搜索 html 页面中的单词 我怎样才能得到这个词所在的html标签 这样我就可以使用整个标签 要查找单词所在的元素 您必须遍历整个树 仅查找文本节点 并应用与上面相同的测试 在文本节点中找到单词后 返回该节点的父节点 var wo
  • 在seaborn中绘制带有孵化的堆积条形图

    我正在尝试使用带有孵化功能的seaborn matplotlib 绘制堆积条形图 但孵化不合适 如图所示 我的代码如下 sc bar sns barplot x Salt Concentration y EPS Produced data
  • Spring 元素必须指定引用或值

    我在 Spring 和构造函数注入方面遇到问题 我想动态创建具有名称的对象 String 和特殊 ID long 但是当加载 spring xml 文件时会发生异常 线程 main 中的异常 java lang ExceptionInIni
  • 将弹出窗口置于前面

    在我的应用程序中 我有一个弹出窗口 其中包含当我选择某些选项时打开的信息 第一次还可以 在所有内容前面弹出突出显示 但是 当它失去焦点时 当用户转到其他窗口时 如果用户再次单击同一选项 我希望弹出窗口再次显示在所有内容的前面 我尝试过类似的
  • iPhone 应用程序的分发(App Store)版本中出现错误

    我创建了一个具有自建照片工具的应用程序 当我测试 调试和临时 时 它工作正常 它是使用 UIScrollView 构建的 并在照片的插槽滚动到屏幕上时将每个照片添加到 UIScroll 视图 但现在该应用程序已在 App Store 中 并
  • 具有多个命令的 Git 别名的语法[重复]

    这个问题在这里已经有答案了 我想创建一个 Git 别名来执行多个命令 但我找不到有关如何完成此操作的文档 具有多个命令的 Git 别名的语法是什么 这是在哪里记录的 来自 man git config alias git 1 命令包装器的命
  • 如何向 R Shiny 表添加行

    我正在尝试使用 R Shiny 构建一个表单 一旦单击表单末尾的操作按钮 它将用于填充表格 我无法弄清楚如何获取表单中的数据并将其添加到表中的新行中 现在 它只是用表单中的任何内容不断更新第一行 我在这里重现了代码的简单版本 ui r li
  • UITabBarController 中的 UIViewController 和 UISplitViewController shouldAutorotateToInterfaceOrientation

    我的 iPad 代码有一些问题 我有一个 UITabBarController 其中包含一些 UIViewController 和 UISplitViewController 问题是 UIViewController 甚至 UISplitV