2017-06-04 89 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”]; –

相关问题