iPhone: Fade transition between two RootViewControllers

为君一笑 提交于 2019-12-21 07:56:52

问题


Obj-C or MonoTouch C# answers are fine.

The initial UIWindow's RootViewController is a simple login screen.

window.RootViewController = loginScreen;

After login, I set the Root to the main app

window.RootViewController = theAppScreen;

How do I Fade-transition between the two RootViewControllers in this instance?


回答1:


I might suggest a different approach that will get you your animation. Just go to the theAppScreen controller first, and if you need the user to log in, have it do the presentViewController to get to the loginScreen (you don't have to animate this step if you want it look like it went directly to the login screen). That way, when you've successfully logged in, the loginScreen can just dismissViewControllerAnimated and you've got your animation back to the main theAppScreen. (Obviously, if you want the fade effect, don't forget to set the controller's modalTransitionStyle to UIModalTransitionStyleCrossDissolve.)

If you're dead set on changing your rootViewController, the only way I can think of doing it (and I don't like it) would be to do something like:

MainAppViewController *controller = [[MainAppViewController alloc] initWithNibName:@"MainAppViewController" bundle:nil];

// animate the modal presentation

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self.window.rootViewController presentViewController:controller 
                                             animated:YES
                                           completion:^{

    // and then get rid of it as a modal

    [controller dismissViewControllerAnimated:NO completion:nil];

    // and set it as your rootview controller

    self.window.rootViewController = controller;
}];

The first technique seems much cleaner to me.




回答2:


This is MT code of @Robert Ryan's technique (although I agree with his suggestion that theAppScreen is probably the "correct" RootViewController):

void DissolveIn (UIWindow window, UIViewController newController)
{
  newController.ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
  window.RootViewController.PresentViewController (newController, true, () => 
  {
    window.RootViewController.DismissViewController (false, null);
    window.RootViewController = newController;
  });
}



回答3:


You can do this:

window.RootViewController = theAppScreen;

loginScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[theAppScreen presentModalViewController:loginScreen animated:NO];

loginScreen can dismiss itself when done: [self dismissModalViewControllerAnimated:YES];

The NO on the first animation will make the loginScreen appear without any visibility of the theAppScreen beneath it. The animated = YES on completion will provide the cross-dissolve.



来源:https://stackoverflow.com/questions/11696277/iphone-fade-transition-between-two-rootviewcontrollers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!