ViewControllers之间的自定义过渡

时间:2017-06-24 13:06:32

标签: ios swift

有人可以解释为什么我的fromViewController是零吗?我试图理解iOS中的自定义过渡动画在两个不同的视图控制器之间来回传递。

删除我的代码的保护部分并稍微修改它,我现在的动画工作,但我无法弄清楚如何实现解雇动画。有什么建议吗?

func animateTransition(using transitionContext: UIViewControllerContextTransitioning)
{
    let containerView = transitionContext.containerView

    guard
        let fromViewController = transitionContext.view(forKey: .from),
        let toViewController = transitionContext.view(forKey: .to)
    else
    {
        print("Nope")
        return
    }

    containerView.addSubview(toViewController)

    if (presentationMode == .Present)
    {
        toViewController.alpha = 0.0

        UIView.animate(withDuration: 1.0,
            animations: {
                toViewController.alpha = 1.0
            },
            completion: {
                _ in transitionContext.completeTransition(true)
        })
    }

编辑:这是我使用动画的地方

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
    let secondVC = segue.destination as! SignUpViewController
    secondVC.transitioningDelegate = self

}
extension LoginViewController: UIViewControllerTransitioningDelegate
{   
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning?
    {
        print("Presenting")

        presentationTransition.presentationMode = .Present

        return presentationTransition
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?
    {
        print("Dismissing")

        presentationTransition.presentationMode = .Dismiss

        return presentationTransition
    }


}`

0 个答案:

没有答案