我总共有4个UIViewControllers。每个视图都有一个按钮,按下时会显示下一个视图控制器。当按下最后一个UIViewController上的按钮时,它会在rootViewController上调用dismissViewControllerAnimated(true,,completion:nil)。当调用它时,它会立即显示View#2,而不是继续使用View#4,因为它会转换回View#1。在文档中,它表示当你这样做时,最顶层的视图是唯一一个在解雇期间将被动画化的视图,但对我来说情况并非如此?如果我使用segues也会发生这种情况。
class ViewController1: UIViewController {
@IBAction func btnDidTouch(sender: AnyObject) {
var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController2") as! UIViewController
self.presentViewController(viewController, animated: true, completion: nil)
}
}
class ViewController2: UIViewController {
@IBAction func btnDidTouch(sender: AnyObject) {
var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController3") as! UIViewController
self.presentViewController(viewController, animated: true, completion: nil)
}
}
class ViewController3: UIViewController {
@IBAction func btnDidTouch(sender: AnyObject) {
var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController4") as! UIViewController
self.presentViewController(viewController, animated: true, completion: nil)
}
}
class ViewController4: UIViewController {
@IBAction func btnDidTouch(sender: AnyObject) {
self.view.window?.rootViewController!.dismissViewControllerAnimated(true, completion: nil)
}
}