本文介绍了iOS 6 UIInterfacePortrait ONLY viewcontroller正在呈现&陷入风景......当从导航堆栈中的横向视图控制器返回时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他许多人一样,我遇到的问题是只有一个或两个视图控制器支持纵向和横向界面方向,在另一个仅限肖像的应用程序中。在iOS 6之前一切正常,但突然自动停止工作。感谢这里的一些很好的问题,我可以通过让初始的navController通过以下方式返回个人topViewController对shouldAutorotate的首选项来解决这个问题:

So like many others, I ran into the problem of only having one or two viewcontrollers support both portrait and landscape interface orientations, in an otherwise portrait only app. Everything worked fine prior to iOS 6, but suddenly autorotating stopped working. Thanks to some great questions here, I was able to resolve that issue by having the initial navController return the individual topViewController's preference for shouldAutorotate via:

    - (BOOL)shouldAutorotate
{
    return  self.topViewController.shouldAutorotate;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

但是,我偶然发现了一个新问题。根vc(viewController A)不应该自动旋转,应该只支持肖像。导航堆栈中的ViewController B支持纵向和横向。如果我在viewController B中,并且处于横向状态,并触摸返回以将视图弹回到viewController A ... vc A加载在横向中,它不应该支持,并且不会旋转回肖像,因为shouldAutorotate for vc A设置为NO ...

However, I have stumbled onto a new problem. the root vc (viewController A) should NOT autorotate and should only support portrait. ViewController B in the nav stack supports portrait and landscape. If I am in viewController B, and am in landscape, and touch "back" to pop the view back to viewController A... vc A loads in landscape, which it is not supposed to even support, and wont rotate back to portrait because shouldAutorotate for vc A is set to NO...

任何有关如何处理此问题的想法都将非常感激。我最初的想法是使用手动方法覆盖vc B的后退按钮,如果视图处于横向状态,则首先强制旋转回纵向...然后将视图控制器弹回到vc A ......但我无法弄清楚如何以编程方式强制旋转。有任何想法吗?

Any ideas on how to deal with this would be greatly appreciated. My initial thought was to override vc B's "back" button with a manual method that first force rotates back to portrait if the view is in landscape... then pops the viewcontroller back to vc A... but I cant figure out how to force a rotation programatically. Any ideas?

这里是vc A中的接口方法:

here are the interface methods in vc A:

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

这是他们在vc B中的内容:

and here is what they are in vc B:

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

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}


推荐答案

在vcA集合中

-(BOOL)shouldAutorotate
{
  return YES;
}

但保持

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationPortrait;
}

然后当您返回时,视图将旋转回(仅)支持的方向来自vcB

Then the view will rotate back to the (only) supported orientation when you return from vcB

这篇关于iOS 6 UIInterfacePortrait ONLY viewcontroller正在呈现&陷入风景......当从导航堆栈中的横向视图控制器返回时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:31