Ios 如何避免父视图控制器旋转

Ios 如何避免父视图控制器旋转,ios,objective-c,rotation,Ios,Objective C,Rotation,我有父视图控制器-在纵向。 我有儿童视图控制器-在景观。 当解除子viewcontroller时,父viewcontroller将保留在横向视图中—不应该这样做。请注意:= 以下是设置: 我的应用程序代理 -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { UIViewCon

我有父视图控制器-在纵向。 我有儿童视图控制器-在景观。 当解除子viewcontroller时,父viewcontroller将保留在横向视图中—不应该这样做。请注意:= 以下是设置:

我的应用程序代理

-(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;
}

从子视图控制器返回时,应调用 在子视图控制器中创建一个方法并实现

- (void)setScreenOrientation:(UIInterfaceOrientation)orientation
{
UIDeviceOrientation deviceOrientation = (UIDeviceOrientation) orientation;
[[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: deviceOrientation] forKey:@"orientation"];
}
在解除之前从子视图调用此选项:

    [self setScreenOrientation:UIInterfaceOrientationPortrait];

    [self dismissViewControllerAnimated:YES completion:nil];

否-不起作用-感谢您的努力@MasumBiswas-在我的childviewcontroller调用应用程序delegate.SetScreenOrientationGrait后,我的父视图控制器仍处于横向视图中。我错过了什么?它为我工作。请直接执行,无需调用函数。无需在应用程序内实现委托即可旋转子视图控制器。您可以在viewdidload中这样做:[[UIDevice currentDevice]设置值:[NSNumber numberWithInteger:UIDeviceOrientation和ScapeLeft]forKey:@orientation];