TransitioningDelegate在Segue过渡后从未打过电话

时间:2016-12-23 13:44:06

标签: swift3 xcode8

所以当我的应用程序从一个View Controller转换到另一个时,我正在尝试实现自定义动画,但由于某种原因,我的自定义动画类中的animateTransition函数永远不会被调用。

为了记录,我正在使用Xcode 8并在Swift 3中编写。我试图解决的问题是,函数永远不会被调用 - 我将在未来理清实际的动画,现在它的

以下是我的CustomPresentAnimationController类中的代码,它应该处理过渡动画......

var response = Client.Search<Person>(s => s.Query(p => p.Match(m => m.Field(f => f.first_name).Query("Marc"))));

以下是我的ViewController的代码(我的两个View Controllers都参考)...

@Transactional(isolation = Isolation.READ_UNCOMMITTED)

当我运行代码,然后单击我提供的按钮(链接到我的seance View Controller)并设置为'Present Modally'时,视图随标准转换(从底部向上滑动)而变化 - 和以下内容打印到Xcode:

import UIKit

class CustomPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate, UINavigationControllerDelegate {

    let duration = 0.5

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        print("Checking duration")
        return duration
    }

    func animationController(forPresented presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        print("This ran 1")
        return self
    }

    func presentationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        print("This ran 2")
        return self
    }

    func animationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        print("This ran 3")
        return self
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

        print("It's working!")

        guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else {
            return
        }

        guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else {
            return
        }

        let container = transitionContext.containerView

        let screenOffDown = CGAffineTransform(translationX: 0, y: -container.frame.height)

        let screenOffUp = CGAffineTransform(translationX: 0, y: container.frame.height)

        container.addSubview(fromView)
        container.addSubview(toView)

        toView.transform = screenOffUp

        UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: {

            fromView.transform = screenOffDown
            fromView.alpha = 0.5
            toView.transform = CGAffineTransform.identity
            toView.alpha = 1

        }) { (success) in
            transitionContext.completeTransition(success)
        }

    }

}

显然第一行就像第一个视图加载一样,所有其余部分显示我的transitionDelegate在Segue目标上设置,并且确实在第二个视图加载时加载,并且transitionDelegate设置为CustomPresentAnimationController ..但是,该类中的所有函数都没有被调用,因为它永远不会从这些函数中打印出任何东西。

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

确保实现委托的方法签名与更新的Swift 3语法匹配。