TheSnakeWizard
TheSnakeWizard

Reputation: 59

how to avoid parent view controller rotating

I have parent viewcontroller - in portrait. I have child viewcontroller - in landscape. When child viewcontroller is dismissed parent viewcontroller remains in landscape- which it should not do. Please advice :=) These are the settings: deployment info

My app delegate

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

Upvotes: 0

Views: 143

Answers (1)

Masum Biswas
Masum Biswas

Reputation: 46

When You back from child view controller you should call Create a method in your child view controller and implement this

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

Call this from child view before dismiss:

    [self setScreenOrientation:UIInterfaceOrientationPortrait];

    [self dismissViewControllerAnimated:YES completion:nil];

Upvotes: 1

Related Questions