Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace window.rootViewController with animation works partially

I'm trying to replace the window rootViewController with animation and it only works partially.

I create a UINavigationController programatically -

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"InboxStoryboard" bundle:nil];

UIViewController *innerViewController = [storyBoard instantiateViewControllerWithIdentifier:@"centerView"];
UINavigationController *centerView = [[UINavigationController alloc] initWithRootViewController:innerViewController];

Afterwards I replace the window root view controller wrapped in an animation block -

[UIView transitionWithView:self.viewController.view.window
                  duration:0.5
                   options: UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    self.viewController.view.window.rootViewController = centerView;
                }
                completion:nil];

What happens is that the animation happen but the controller that I create is only partially visible, take a look at the following picture -

So as you can see during the rotation the view is only partially rendered.

Anyone bumped into this kind of behaviour before?

like image 322
Nimrod Gutman Avatar asked Nov 11 '12 15:11

Nimrod Gutman


1 Answers

So after a long search I found the problem was in the [UIView transitionWithView:...] Searching a bit more in stackoverflow I found Swapping rootViewController with animation

Using [UIView transitionFromView:..] works perfectly.

The new code -

[UIView transitionFromView:self.window.rootViewController.view
                    toView:self.centerViewController.view
                  duration:0.5
                   options:UIViewAnimationOptionTransitionCurlUp
                completion:^(BOOL finished)
                {
                    self.window.rootViewController = self.centerViewController;
                }];
like image 85
Nimrod Gutman Avatar answered Oct 05 '22 23:10

Nimrod Gutman