2017-06-04 90 views
0

我有父視圖控制器 - 肖像。 我有孩子viewcontroller - 橫向。 當子視圖控制器被解僱時,父視圖控制器保持在風景中 - 它不應該這樣做。請諮詢:=) 這些設置: deployment info如何避免父視圖控制器旋轉

我的應用程序委託

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    UIViewController* topVC = [self getTopController]; 
    if ([topVC isKindOfClass: [childVideoViewController class]]) { 
     return UIInterfaceOrientationMaskLandscape; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(UIViewController*) getTopController{ UIViewController *topViewController =  [UIApplication sharedApplication].keyWindow.rootViewController; 

    while (topViewController.presentedViewController) { 
     topViewController = topViewController.presentedViewController; 
    } 
    return topViewController; 
} 

回答

1

當您從子視圖控制器回你應該叫 創建你的子視圖控制器的方法和實施此

- (void)setScreenOrientation:(UIInterfaceOrientation)orientation 
{ 
UIDeviceOrientation deviceOrientation = (UIDeviceOrientation) orientation; 
[[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: deviceOrientation] forKey:@"orientation"]; 
} 

調用此從子視圖之前解僱:

[self setScreenOrientation:UIInterfaceOrientationPortrait]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 
+0

否 - 它不工作 - 感謝您的努力@ MasumBiswas - 我的父視圖控制器仍然在橫向後,我的childviewcontroller調用應用程序delegate.setscreenorientation(肖像)。我錯過了什麼? – TheSnakeWizard

+0

它爲我工作。請不要直接調用函數 –

+0

不需要在應用程序委託中實現來旋轉你的子視圖控制器。你可以在viewdidload中這樣做:[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@「orientation」]; –

相關問題