假设我有一个UIViewControllerAnimatedTransitioning
,显示为一个弹出框。在视图之间切换时,它的委托引用了一个自定义func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AnimationController(presenting: (operation==.push)
}
类:
class ViewController: UIViewController {
...
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.preferredContentSize = self.preferredContentSize
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.preferredContentSize = self.preferredContentSize
}
}
但是,推送的视图具有不同的首选内容大小:
preferedContentSize
当前,当我将视图控制器推到堆栈上时,我看到我的自定义动画已执行,然后更改了弹出窗口的大小。如何在动画运行的同时调整弹出窗口的大小?设置animateTransition(using: ...)
或从func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let toView = transitionContext.view(forKey: .to) else { return }
transitionContext.containerView.addSubview(toView)
toView.alpha = 0.0
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
toView.alpha = 1.0
}) { _ in
let success = !transitionContext.transitionWasCancelled
if !success {
toView.removeFromSuperview()
}
transitionContext.completeTransition(success)
}
}
内部调整约束似乎无效。
{{1}}