在TabbarController的NavigationController中强制UIViewController旋转
问题描述:
我已经有了这样的View层次结构。在TabbarController的NavigationController中强制UIViewController旋转
UITabBarController
|
UINavigationController
| |
| UIViewController
|
UINavigationController
|
UIViewController
的事情是,我有一个只能在肖像显示一个视图控制器,只要我打开设备到另一个景观视图控制器被放在上面推,即工作作为迄今预期。
我现在想的是,只要我推在新弹出的ViewController后退按钮,旧的ViewController被强制人像,即使设备仍处于风景。
我已经尝试过渡,但随后其他视图被搞砸了,不能正确识别那里的方向,导致混乱的*的意见。
答
只为我工作的事情,用
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
在我的ViewController与presentModalViewController呈现它。 这会强制View保持风景。 不完全是我想要的,但它解决了。下面
答
尝试添加该原始视图控制器:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
return NO;
}
这应该迫使它只能以纵向显示。
答
该代码将迫使视图到风景模式,但仅当父视图控制器支持横向模式。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
如果你想强行进入横向模式视图的父视图控制器只有肖像,你必须创建一个新的新的导航控制器。最简单的方法是在模态视图中显示强制横向视图控制器。因此,使用presentModalViewController而不是pushViewController。
可悲的是,这也不工作。由于设备已处于横向模式,因此它可能会认为:“好吧,我会保持原样。”出现这种情况的唯一的事情是,这两种观点之间的过渡动画是错误的(从上到下而不是从右至左) – muffe
你可能是对的,我只曾经与一个模式视图控制器使用此。 –