UIViewController自定义转换从TransitionContext

时间:2017-10-25 12:05:42

标签: ios swift animation uiviewcontroller uiviewanimationtransition

我正在为ViewController Presentation进行自定义转换。我遇到的是TransitionContext中的 fromViewController 具有错误的类类型。它应该是 UICustomXXXXXViewController ,而它显示为 UINavigationController 。奇怪的是 toViewController 确实给出了正确的类型。

我有一个PresentationStrategy类:

class PresentationStrategy: NSObject {
    private let animator: BaseTransitioningAnimator

    init(animator: BaseTransitioningAnimator) {
        self.animator = animator
    }

    static var resultDetailBouncyExpand = PresentationStrategy(animator: BouncyExpandAnimator(duration: 0.9))

}

extension PresentationStrategy: UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController,
                             presenting: UIViewController,
                             source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        animator.transitionType = .present
        return animator
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        animator.transitionType = .dismiss
        return animator
    }
}

在动画师的animationTransition函数中,我只需调用

let fromViewController = transitionContext.viewController(forKey: .from)!

因为我需要在呈现视图控制器中访问某些内容,所以我需要将它转换为特定的类。但是当它被证明不是表现它的类的类型时。

Printing description of fromViewController:
<UINavigationController: 0x7fac0580e000>

这就是我如何呈现它

presentedVC.transitioningDelegate = PresentationStrategy.resultDetailBouncyExpand
        presentingVC.present(presentedVC, animated: true)

0 个答案:

没有答案