2015-02-06 179 views
0

我在做this,试图在风景中看到一个画廊,但是当我将模型与主ViewController连接时,我只能看到风景方向:导航模式视图控制器和导航控制器的层次结构

RootViewController的 - (模态赛格瑞)>图片集锦

的问题是,当我这样做:

Rootviewcontroler - (模态赛格瑞)> ViewControllerModal - (模态赛格瑞)>图片集锦

它不工作,也不作品与导航控制器:

RootViewController的 - (模态赛格瑞)> NavigationController A - (推赛格瑞)> NavigationController乙 - (模态赛格瑞)>图片集锦

我不知道如何导航层级多达内supportedInterfaceOrientationsForWindow画廊,以及:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 

if ([self.window.rootViewController.presentedViewController isKindOfClass: [PhotoGallery class]]){ 
    PhotoGallery *photoGallery = (PhotoGallery *) self.window.rootViewController.presentedViewController; 
    if (photoGallery.isPresented) return UIInterfaceOrientationMaskLandscape; 
    else return UIInterfaceOrientationMaskPortrait; 
} 

return UIInterfaceOrientationMaskPortrait; 

}

在此先感谢。

回答

0

我不得不为一个电子商务应用程序做一次这样的事情,并且必须呈现一个签名屏幕,而该应用程序的其余部分是纵向的。为了退出这个功能,我们首先建立在UIViewController的一个类别,支持强制取向

@implementation UIViewController (ForcedOrientation) 

-(UIInterfaceOrientationMask)forcedOrientation { 
    // Default implementation is to return none (i.e. no forced orientations); 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(void) forceOrientationAdjustment { 
    UIViewController *root = [[[UIApplication sharedApplication] keyWindow] rootViewController]; 
    UIViewController *dummy = [[UIViewController alloc] init]; 
    [root presentViewController:dummy animated:NO completion:^{ 
     [root dismissViewControllerAnimated:NO completion:nil]; 
    }]; 
} 

@end 

然后,我们的子类的UINavigationController和推翻了以下方法:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    UIViewController *visibleVC = self.topViewController; 

    // Need to find out what the actual "top screen" is 
    while (visibleVC) { 
     if ([visibleVC isKindOfClass:[UINavigationController class]]) { 
      visibleVC = [(UINavigationController*)visibleVC topViewController]; 
      continue; 
     } 
     break; 
    } 

    NSUInteger forcedOrientation = [visibleVC forcedOrientation]; 
    if (forcedOrientation) { 
     return forcedOrientation; 
    } else { 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 

的最后一步是添加一个forcedOrientation调用我们想要呈现的视图控制器,并在我们的viewDidAppear方法中添加一个调用forceOrientationAdjustment:

- (UIInterfaceOrientationMask) forcedOrientation { 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(void) viewDidAppear:(BOOL)animated { 
... 
    [self forceOrientationAdjustment] 
... 
} 

虽然这个工作非常完美,但对我来说,它总是感觉像一个黑客。我们必须非常快速地展示这个假视图控制器,以便改变方向。有可能有更好的解决方案,也许这一个:How to force a UIViewController to Portrait orientation in iOS 6

祝你好运!

+0

谢谢,我会尝试。 – Javier 2015-02-07 08:54:02

相关问题