您需要等待动画完成后才能执行E:
class ViewController: UIViewController {
@IBAction func unwindToA(segue: UIStoryboardSegue) {
}
@IBAction func unwindToE(segue: UIStoryboardSegue) {
CATransaction.begin()
CATransaction.setCompletionBlock {
self.performSegue(withIdentifier: "E", sender: nil)
}
CATransaction.commit()
}
}
更新
避免
闪烁
显示按下E的同时
1) 取消展开功能:
extension ViewController {
@IBAction func unwindToA(segue: UIStoryboardSegue) {
}
// @IBAction func unwindToE(segue: UIStoryboardSegue) {
// CATransaction.begin()
// CATransaction.setCompletionBlock {
// self.performSegue(withIdentifier: "E", sender: nil)
// }
// CATransaction.commit()
// }
}
2) 创建自定义序列:
class MyUnwindSegue: UIStoryboardSegue {
override func perform() {
guard let nav = source.navigationController else { return }
guard let root = nav.viewControllers.first else { return }
let viewControllers = [root, destination]
nav.setViewControllers(viewControllers, animated: true)
}
}
3) 将序列图像板中的segue更新为MyUnwindSegue(确保将模块选择为项目模块,而不是
空的
):