7

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Nimrod Gutman
  • 1,027
  • 1
  • 10
  • 21
  • a bug? delete the app on simulator and run it again. – MasterRazer Nov 11 '12 at 16:40
  • What is self in the code you posted? It's not clear what class you're executing this code in. – rdelmar Nov 11 '12 at 17:41
  • self is some NSObject another UIViewController have. The flow is - Instantiate my object in some other UIViewController, use the object to replace the root view controller with another one. AFAIK this is pretty standard flow, still no idea why it's partially rendered. Also if I don't use animation and just replace the root view it works. – Nimrod Gutman Nov 12 '12 at 07:19

2 Answers2

16

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;
                }];
Community
  • 1
  • 1
Nimrod Gutman
  • 1,027
  • 1
  • 10
  • 21
  • Is this code really working?? This should not work because this will give compile time warning... you are assigning UIView to rootViewController property... which is wrong... Please correct your answer... – DShah May 20 '13 at 08:01
0

Are you using Auto layout? If so, try disabling it. I have run into multiple problems with auto layout and animations.

user1819329
  • 411
  • 3
  • 9