UIViewControllerAnimatedTransitioning animate предпочитаемыйContentSize - PullRequest
0 голосов
/ 21 января 2019

Предположим, у меня есть UINavigationController, который представлен как поповер. При переходе между представлениями его делегат обращается к пользовательскому классу 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)
        }
    }
...