2015-02-06 192 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

相關問題