OStack程序员社区-中国程序员成长平台

标题: ios - 更改rootViewController时从正确的动画滑动 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:21
标题: ios - 更改rootViewController时从正确的动画滑动

我正在尝试使用从右滑动的动画来更改rootViewController。

我知道如何使用翻转动画:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("LandingViewController") 


UIView.transitionWithView( UIApplication.sharedApplication().keyWindow!,
                           duration: 0.5,
                           options: UIViewAnimationOptions.TransitionFlipFromLeft,
                           animations: { UIApplication.sharedApplication().keyWindow?.rootViewController = viewController; },
                           completion: nil)

但是,UIViewAnimationOptions没有从右向滑动的动画。
我该如何实现?



Best Answer-推荐答案


试试这个

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("LandingViewController") 

let navigationController = UIApplication.sharedApplication().keyWindow?.rootViewController.navigationController

//first push the viewController
navigationController?.pushViewController(viewController, animated: true)

然后,在viewController的viewDidAppear处,您应该执行此代码
//remove all previous controllers in the stack by settings viewControllers stack with only current viewController
self.navigationController?.viewControllers = [self]

希望对您有所帮助

关于ios - 更改rootViewController时从正确的动画滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39133255/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4