【问题标题】:Autorotate parent view to portrait when child view is dismissed ios6ios6关闭子视图时将父视图自动旋转为纵向
【发布时间】:2013-04-04 11:47:03
【问题描述】:

导航控制器中嵌入的登录视图控制器必须是纵向的。 其他视图控制器的 push 可以旋转。 设想: 如果登录后我旋转子视图控制器,然后注销登录视图控制器以横向显示。

logincontroller(portrait)->rotated device->childcontroller(landscape)->back->logincontroller(landscape)

我希望登录控制器在我回来时是纵向的。

【问题讨论】:

    标签: xcode ios6 xcode4.5


    【解决方案1】:

    在你的登录 ViewController 中输入这两个方法

    - (BOOL)shouldAutorotate {
        return YES;    
    }
    
    - (NSUInteger)supportedInterfaceOrientations {    
        return (UIInterfaceOrientationMaskPortrait | 
                UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    

    - (BOOL)shouldAutorotate {
        return YES;    
    }
    
    - (NSUInteger)supportedInterfaceOrientations {    
        return (UIInterfaceOrientationLandscapeRight | 
                UIInterfaceOrientationLandscapeLeft);
    }
    

    在您的子控制器中

    【讨论】:

    • 我还需要添加类别自动旋转子类导航控制器,它将调用 topcontroller shouldautorotate 并支持界面方向。
    【解决方案2】:

    在你的登录 ViewController 中输入这两个方法

    (BOOL)shouldAutorotate { return YES;
    }
    
    (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown); }
    

    (BOOL)shouldAutorotate { return YES;
    }
    
    (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft); }
    

    在您的子控制器中

    需要添加类别自动旋转子类导航控制器,该控制器将调用 topcontroller shouldautorotate 并支持界面方向。

    #import "UINavigationController+Autorotation.h"
    
    @implementation UINavigationController (Autorotation)
    -(BOOL)shouldAutorotate
    {
    for (UIViewController * viewController in self.viewControllers) {
        if (![viewController isEqual:self.topViewController]) {
            [viewController shouldAutorotate];
        }
    }
    
    return [self.topViewController shouldAutorotate];
    
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
    for (UIViewController * viewController in self.viewControllers) {
        if (![viewController isEqual:self.topViewController]) {
            [viewController supportedInterfaceOrientations];
        }
    }
    
    return [self.topViewController supportedInterfaceOrientations];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多