0

When a user presses a logout button inside another view controller, I use notification center to fire a selector in app delegate. I want the fired method to animate a flip back to the login view controller in the app delegate.

Here is my first attempt:

LoginViewController *loginController = [[LoginViewController alloc] init];
[UIView transitionFromView:self.window.rootViewController.view
                    toView:loginController.view
                  duration:3.0f
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                completion:^(BOOL finished){
                    self.window.rootViewController = loginController;
                }];

This does not work, as the rootViewController gets set instantaneously with no animation.

Here is my second attempt (as referenced here: RootViewController Switch Transition Animation)

   [UIView transitionWithView:self.window
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{ self.window.rootViewController = [[LoginViewController alloc] init]; }
                completion:nil];

This almost works, but the animation is very buggy - you can see misplaced views, stretched elements, etc during the animation and it's clear that it's not animating like you'd expect.

Any idea what the right way to do this animation is?

Community
  • 1
  • 1
Ken
  • 530
  • 4
  • 11
  • 30
  • You should be using an navigation controller to control your navigation. Flipping animation isn't included in the transitions so you could do something like this: http://stackoverflow.com/questions/18982724/flip-transition-uinavigationcontroller-push – jakedunc Aug 01 '15 at 08:26
  • Does this let me set the root view controller though? I'm pretty sure that's essential to truly reset to the login state - otherwise I believe all the other view controllers will still be on the stack in memory, even if they're inaccessible. – Ken Aug 01 '15 at 08:32

0 Answers0