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

时间:2012-07-27 22:07:38

标签: iphone ios xamarin.ios transition

Obj-CMonoTouch C#答案很好。

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

window.RootViewController = loginScreen;

登录后,我将Root设置为主应用程序

window.RootViewController = theAppScreen;

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

3 个答案:

答案 0 :(得分:19)

我可能会建议一种能让你动画的不同方法。只需先转到theAppScreen控制器 ,如果您需要用户登录,请让presentViewController转到loginScreen(您不要如果您希望它看起来像直接进入登录屏幕,则必须为此步骤制作动画。这样,当您成功登录后,loginScreen就可以dismissViewControllerAnimated,您可以将动画恢复到主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;
}];

第一种技术对我来说似乎更清洁。

答案 1 :(得分:3)

这是@Robert Ryan技术的MT代码(尽管我同意他的建议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;
  });
}

答案 2 :(得分:1)

你可以这样做:

window.RootViewController = theAppScreen;

loginScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[theAppScreen presentModalViewController:loginScreen animated:NO];
完成后,

loginScreen可以自行解除:[self dismissModalViewControllerAnimated:YES];

第一个动画上的NO将使登录屏幕显示,而不显示其下方的应用程序屏幕。完成后的动画= YES将提供交叉溶解。

相关问题