- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个以 TabBarController 作为根 Controller 的 iphone 应用程序。并且此根 Controller 与导航 Controller 相关联(每个导航 Controller 都与特定的选项卡栏按钮相关)。
这些导航 Controller 上的一个显示了一些照片,因此我需要启用 Lanscape,这显然在我将此代码添加到所有 View Controller 之前不起作用
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
但是,现在在所有 View 中都启用了所有方向,一些我不想在横向中显示的 View 非常难看:(
知道如何仅在此照片 View 上保留横向方向并在所有其他 View 上禁用它吗?
最佳答案
考虑以模态方式显示需要完全重新定向功能的 UIViewController。在我看来,这是处理这种情况的常见且正确的方法。
简短地回答您的主题:是的,如果您希望任何选项卡式 viewController 允许重新定向,它确实必须返回 YES
。 UINavigationControllers
堆栈中的 viewControllers 也是如此。因此,这同样适用于它们的任意组合。
摘自 Apple 关于该主题的技术说明:
Why won't my UIViewController rotate with the device?
All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set. To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.
如果使用模态呈现的 View Controller 不适合您 - 这里有另一种方式......
还有一个可能的解决方案看起来有点“hacky”,但过去对我有用。我将以非常非常“hacky”的方式起草它以简化答案。
在所有 View Controller 的 shouldAutorotateToInterfaceOrientation:toInterfaceOrientation 实现中,返回一个全局值。根据当前显示的 viewController 的需要更改该全局值。尽管据说 viewController 只被询问一次,但这个常见的谣言已被证明对我来说是不正确的。 super 黑客来了;
导航堆栈中的所有 View Controller 都应该像这样实现 shouldAutorotate 方法:
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation
{
extern BOOL gSouldAutorotateToAnyOrientationFlag;
if (gShouldAutorotateToAnyOrientationFlag)
{
return YES;
}
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
现在,在您应用的某处,您应该声明并实例化该全局标志 - 您可以将这个丑陋的全局标志放置在您的应用委托(delegate)实现中,直接位于导入下方和@implementation block 上方:
BOOL gShouldAutorotateToAnyOrientationFlag = NO;
在所有应该仅以纵向模式显示的 viewController 中,将该标志设置为 NO - 例如在 viewWillAppear 内;
- (void)viewWillAppear:(BOOL)animated
{
extern BOOL gShouldAutorotateToAnyOrientationFlag;
gShouldAutorotateToAnyOrientationFlag = NO;
}
在应该以任何方向显示的 viewController/s 中,将该标志设置为 YES - 再次在 viewWillAppear 中;
- (void)viewWillAppear:(BOOL)animated
{
extern BOOL gShouldAutorotateToAnyOrientationFlag;
gShouldAutorotateToAnyOrientationFlag = YES;
}
这样,每当询问整个导航堆栈的方向功能时,都会给出正确的答案。根据我的经验,整个堆栈会被一遍又一遍地询问,答案不会被缓存,因此我的 hack 在我需要的时候起作用了。不过,谣言似乎很普遍,这些答案以某种方式被缓存,因此谣言在某些情况下可能是有效的——因此,如果这对你不起作用(或者甚至被否决:D),我将不承担任何责任
关于iphone - TabBar 应用程序是否需要 shouldAutorotateToInterfaceOrientation 在其所有 viewController 上返回 YES?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8404389/
我现在在另一个 ViewController 之上展示了一个几乎透明的 ViewController,但它禁用了与下面的 ViewController 的交互。这是我目前使用的代码: topContr
我有一个 View Controller ,其工具栏上有 3 个 UIButtons,可以打开一个新的 View Controller 作为弹出窗口。我在 Storyboard 中创建了 Segues
这个问题在这里已经有了答案: Delegates in swift? (15 个答案) 关闭 3 年前。 在我的场景中,我试图在关闭 View Controller 期间将值从 ViewContro
假设我有两个 viewController,AViewController 和 BViewController。 AViewController 嵌入在 NavigationController 中(
我有 3 个 View Controller A、B 和 C。 我在 vcA 上,我使用 推送 vcB [self.navigationController pushViewController:vc
我想知道如何在 VC3 和 VC1 之间传递数据。 我拥有的是 Root View (VC1)。然后你输入一个tableView,如果你选择一个项目,你将进入tableView2(VC3) - 类别
我在使用 Unwind Segue 时遇到问题。我有 3 个 ViewController,它们都在名为 ViewController.swift 的类下。我试图获取最后一个 ViewControll
我有一个应用程序,其左上角有一个汉堡菜单。按下时,菜单会以 90% 的不透明度淡入当前 ViewController,显示应用程序的主要导航选项。 我使用下面的代码从页面呈现 viewControll
我的问题是,当我呈现一个 UIViewController 时,呈现的 View 变黑了。 我有一个名为 mainViewController 的 UIViewController,它是我窗口的 Ro
例如,当我呈现UIActivityViewController或UIAlertController时,我仍然可以看到背景viewController,我不想在viewContollerA中嵌入view
我从second viewController进入了third viewController,但是我不想回到第二个viewController,我需要直接回到我的第一个viewController,我
我的应用程序是标签栏(+ 导航)应用程序。在 FirstViewController 中,我调用 onModalView。 -(void) onFilter { FilterViewControl
Photo Sharing 部分是我写的一个ViewController,当我按下正确的项目时,PhotoSharingViewController 会动画出现。 这是我的代码: PhotoShari
我正在尝试在另一个 View Controller 中使用 subview Controller 的应用程序。我有一个 VC,我正在实例化另一个 VC,并在外部 VC 内使用它自己的 xib。 我使用
我正在寻找有关包含 ViewController 的滚动的想法。我需要知道包含 View Controller 的位置。我已经尝试过 UIPageViewController 但我无法让滚动委托(de
我有一个带有嵌入式 NavigationController 的基本 ViewController 来提供工具栏。 ToolBar 有三个按钮,用于通过 segue 调用 ViewController
我的应用程序中的伙计们,我在应用程序委托(delegate)方法中有一些代码 application:didFinishLaunchingWithOptions:确定初始 View Controlle
我遇到了一个问题,我将对此进行描述,并且发现了一些类似的问题,但我认为与我的问题无关。 我有一个 UITabBarController,其中有 2 个用于 VC1 和 VC2 的选项卡。 VC1 转到
我的应用程序中有一个计时器。如果计时器达到 0,则用户将被带到失败页面。当这种情况发生时,之前的 ViewController 没有被关闭,导致更多的内存被占用。 如果出现失败页面,我希望关闭之前的
在问这个问题之前,我当然做了一些调查。我在 google 和 stackoverflow 上找到的链接或主题之一是: How do I load another view controller fro
我是一名优秀的程序员,十分优秀!