OGeek|极客世界-中国程序员成长平台

标题: ios - UIView transitionWithView 自定义动画选项 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:31
标题: ios - UIView transitionWithView 自定义动画选项

我有一个首先显示登录屏幕的应用程序。用户登录后,将执行以下代码:

[UIView transitionWithView:self.view.window
                              duration:0.7
                               options:UIViewAnimationOptionTransitionNone
                            animations:^{
                                self.view.window.rootViewController = menuController;
                            } completion:^(BOOL finished) {
                                // Code to run after animation

                            }];

这按预期工作;但是,我想定义我自己的自定义动画选项,而不是从左/右翻转选项。

一个简单的例子是将新的 View Controller 从上到下滑动到屏幕上。更改 rootViewController 时如何执行此操作?

另外,是否有完全不同的动画切换 rootViewController 的方法?我不喜欢这个解决方案,它只是我可以通过 Google/SO 搜索找到的最接近的东西。

任何帮助都会很棒,谢谢!



Best Answer-推荐答案


使用 CATransition 应该能够为您提供您正在寻找的那种动画。诚然,我从未真正尝试过专门使用 rootViewController 进行此操作,但要将 View 从上到下滑动,我建议尝试以下操作:

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionFromBottom;
transition.subtype = kCATransitionFade;

CALayer *layer = self.view.window.rootViewController.view.layer;
[layer addAnimation:transition forKey:kCATransition];

关于ios - UIView transitionWithView 自定义动画选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704707/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4