ios - 更改rootViewController时从正确的动画滑动
<p>我正在尝试使用从右滑动的动画来更改rootViewController。<br><br>我知道如何使用翻转动画:<br><pre><code>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)
</code></pre><br>但是,UIViewAnimationOptions没有从右向滑动的动画。<br>我该如何实现?</p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p>试试这个<br><pre><code>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)
</code></pre><br>然后,在<code>viewController</code>的viewDidAppear处,您应该执行此代码<br><pre><code>//remove all previous controllers in the stack by settings viewControllers stack with only current viewController
self.navigationController?.viewControllers =
</code></pre><br>希望对您有所帮助</p>
<p style="font-size: 20px;">关于ios - 更改rootViewController时从正确的动画滑动,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39133255/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39133255/
</a>
</p>
页:
[1]