iPhone:两个RootViewController之间的淡入淡出过渡

Obj-CMonoTouch C#答案很好。

最初的UIWindow的RootViewController是一个简单的login屏幕。

 window.RootViewController = loginScreen; 

login后,我将根设置为主应用程序

 window.RootViewController = theAppScreen; 

如何在这个实例中的两个RootViewController之间进行淡入淡出?

我可能会build议一个不同的方法,让你的animation。 首先进入theAppScreen控制器,如果你需要用户login,就让它做presentViewControllerloginScreen (如果你想让它看起来像是直接进入login屏幕)。 这样,当您成功login后,loginScreen可以dismissViewControllerAnimated并将animation回到主theAppScreen 。 (显然,如果你想要淡入淡出的效果,不要忘记将控制器的modalTransitionStyle设置为UIModalTransitionStyleCrossDissolve 。)

如果你不想改变你的rootViewController ,我能想到做的唯一方法(我不喜欢它)将是这样做的:

 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; }]; 

第一种技术似乎比我更清洁。

这是@Robert Ryan技术的MT代码(尽pipe我同意他的build议,即theAppScreen可能是“正确”的RootViewController ):

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

你可以这样做:

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

loginScreen完成后可以closures自己: [self dismissModalViewControllerAnimated:YES];

第一个animation中的NO将使login屏幕出现,而不显示其下的AppScreen。 完成animation=是将提供交叉溶解。