【问题标题】:Support Landscape for one UIViewController and Portrait for Others in UINavigationController Stack在 UINavigationController Stack 中支持一个 UIViewController 的 Landscape 和其他 UIViewController 的 Portrait
【发布时间】:2013-09-06 06:19:23
【问题描述】:

我有 4 个 UIViewControllers -- 命名为 ControllerA、ControllerB、ControllerC、ControllerD。

其中 ControllerA 是 UINavigationStack 中的 RootViewController。

ControllerA *ca = [[ControllerA alloc]initWithNibName:@"ControllerA" bundle:nil];
UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:ca];
self.window.rootViewController = nv;

在推送 ControllerB 之后,它们都处于肖像状态,但问题来了,我希望控制器 C 处于横向状态。

我已经阅读了许多代码,但有任何令人满意或可行的解决方案,但我确实设法通过沿角度变换视图来旋转它 --

[[UIApplication sharedApplication]]setStatusBarOrientation:UIInterfaceOrientationLandscapeRight
animated:YES];
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

但是现在我想在控制器C上以模态方式呈现ControllerD,如果它通过一些旋转它不会进入横向,它会干扰所有其他视图控制器变换。

做了这么多之后,我又遇到了同样的问题,即通过一些记录的方法在景观中制作 ControllerC。

【问题讨论】:

    标签: ios uiviewcontroller uiinterfaceorientation


    【解决方案1】:

    对于纵向模式 VC,

    #pragma mark iOS 5 Orientation Support
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
         return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    #pragma mark iOS 6 Orientation Support
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    对于横向模式 VC,

    #pragma mark - iOS 5.0 and up Rotation Methods
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        return UIInterfaceOrientationMaskLandscape;
    
    }
    
    #pragma mark - iOS 6.0 and up Rotation Methods
    
    - (NSUInteger)supportedInterfaceOrientations;
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    【讨论】:

    • Karthika 这不会强制一个控制器处于横向,因为当导航堆栈中的控制器时,它们会跟随其根视图控制器,如果根视图是 potrait,那么所有视图都将在 potrait 中,如果它在横向则所有将是横向的。
    • 在我的应用程序中,我的第一个、第二个、第三个视图控制器是纵向的。在第四个视图控制器处于横向模式。我已经像这样在每个视图控制器中处理了方向。并且在 Plist 中所有方向都处于启用状态。
    • 妈妈在执行此操作时将进入横向 -- SecondScreen *ss = [[SecondScreen alloc]initWithNibName:@"SecondScreen" bundle:nil];[self.navigationController presentViewController:ss animated:YES完成:无];但不是当我将它推到 uinavigationcontroller 上时。还有什么我需要做的吗?
    • 谢谢,我根据你的回答让它工作了,但它仍然不能用于导航,但是没有它的工作是可以的。非常感谢
    • 查看此链接,stackoverflow.com/questions/18645782/…。尝试使用 UINavigationController 类别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多