我正在尝试使用从右滑动的动画来更改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-推荐答案 strong>
试试这个
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/
|