navigationController(_ navigationController:, animationControllerFor:, from:, to:)
来返回一个自定义的 UIViewControllerAnimatedTransitioning
对象。如果您选择这种方法,则必须完全自己实现整个动画。viewWillAppear:
和/或 viewWillDisappear:
。在其中您可以获取 transitionCoordinator
并在其上调用 animate(alongsideTransition:, completion:)
。通过这种方式,您可以将自定义动画与系统提供的动画并行运行。override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
let fixedViewCopy = UIView(...)
fixedViewCopy.frame = self.fixedView.frame
transitionCoordinator?.animate(
alongsideTransition: { context in
context.containerView.addSubview(fixedViewCopy)
},
completion: { _ in
fixedViewCopy.removeFromSuperview()
}
)
}