简体   繁体   English

两个Modal ViewControllers之间的动画过渡

[英]Animated Transition between two Modal ViewControllers

I'm trying to switch between two different active Modal View Controllers and trying for a smooth animation. 我正在尝试在两个不同的活动模态视图控制器之间切换并尝试平滑动画。 Ideally I would like to have the animation look just like the new Modal View is becoming a Modal View over the current Modal View. 理想情况下,我希望动画看起来就像新的Modal View正在成为当前模态视图的模态视图。

For consistency across my application, I need to limit only one layer of Modal View Controllers displayed at any given time. 为了在我的应用程序中保持一致性,我需要限制在任何给定时间显示的一层模态视图控制器。

Currently I just have the existing Modal View dismiss with no animation and then animate the next Modal View over the RootController, but this doesn't look nice. 目前我只是现有的模态视图解除没有动画,然后通过RootController动画下一个模态视图,但这看起来不太好。

Thanks 谢谢

You can just present the 2nd model view controller over the first using the default transition. 您可以使用默认转换在第一个上显示第二个模型视图控制器。 It sounds like your second model view is being allocated and initialized in the same view controller as your first model view. 听起来您的第二个模型视图在与第一个模型视图相同的视图控制器中进行分配和初始化。 If this is the case, consider refactoring your code so that you would have the first model view controller present the second modal view controller. 如果是这种情况,请考虑重构代码,以便让第一个模型视图控制器显示第二个模态视图控制器。 Doing this would display one over the other like you want. 这样做会像你想要的那样在另一个上面显示。

If you need to keep the code for presentation of both modal view controllers in the same root view controller, you may want to create a delegate method. 如果需要在同一个根视图控制器中保留用于显示两个模态视图控制器的代码,则可能需要创建委托方法。 This would send a message from the first modal view controller back to the root view controller that presented it, passing along a reference to the first modal view controller. 这会将消息从第一个模态视图控制器发送回呈现它的根视图控制器,并将引用传递给第一个模态视图控制器。 Next, use this reference to tell the first modal view controller to present the 2nd modal view controller over it. 接下来,使用此引用告诉第一个模态视图控制器在其上显示第二个模态视图控制器。

I'd definitely recommend the former solution though as it's logically clearer with less chance of introducing a retain cycle. 我肯定会推荐前一种解决方案,因为它在逻辑上更清晰,引入保留周期的可能性更小。

In response to your clarification: 回应您的澄清:

To transition between two, try: 要在两者之间转换,请尝试:

In your ModalViewControllerOne instance that is already displayed from a previous session: 在已从上一个会话中显示的ModalViewControllerOne实例中:

self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self dismissModalViewControllerAnimated:YES];

In your rootViewController's -viewDidAppear: 在你的rootViewController的-viewDidAppear:

ModalViewControllerTwo *modalViewControllerTwo = [[ModalViewControllerTwo alloc] init];
modalViewControllerTwo.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[rootViewController presentModalViewController:modalViewControllerTwo animated:YES];

The idea of this is to cross-dissolve the first modal view controller back to the root view controller, then immediately cross-dissolve the new modal view controller back onto the screen. 这样做的想法是将第一个模态视图控制器交叉溶解回根视图控制器,然后立即将新的模态视图控制器交叉溶解回屏幕。

If it's just the view that is different between the splash screens, you could instead of two view controllers, have one view controller with logic in that simply swaps out one view for the other depending on the URL entered and use an animation when swapping between the views. 如果它只是启动屏幕之间不同的视图,则可以代替两个视图控制器,让一个视图控制器具有逻辑,根据输入的URL简单地为另一个视图交换一个视图,并在交换时使用动画观点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM