Manually adding the rootViewController’s view to the view hierarchy is no longer supported. Please allow UIWindow to add the rootViewController’s view to the view hierarchy itself.

I was having this issue when setting a new rootViewController from loginViewController , which was a rootViewController in the storyboard before the transition.

SSAHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"sIdHomeNavController"];

        [UIView transitionFromView:self.view
                            toView:homeViewController.view
                          duration:0.5
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        completion:^ (BOOL finished) {
                            if (finished) {
                                [[[UIApplication sharedApplication] windows] firstObject].rootViewController = homeViewController;
                            }
                        }];

I was not sure what was the problem. Since this works perfect on iOS 13 if I don’t use the [UIView transitionFromView] but I wanted to keep the animation effect, it looked good.

I decided to made a simple trick, by using a dummy view. Which solved this problem.

SSAHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"sIdHomeNavController"];

        UIView *dummyView  = [[UIView alloc] initWithFrame:self.view.frame];
        dummyView.backgroundColor = [UIColor whiteColor];
        
        [UIView transitionFromView:self.view
                            toView:dummyView
                          duration:0.5
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        completion:^ (BOOL finished) {
                            if (finished) {
                                [[[UIApplication sharedApplication] windows] firstObject].rootViewController = homeViewController;
                            }
                        }];

instead of using homeViewController.view we use dummy view for the animation and white as its background, otherwise you will see black background between transitions.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •