当分离到从NSObject继承的自定义类时,TransitioningDelegate对UIPresentationController不起作用

时间:2015-06-29 07:08:07

标签: swift delegates uipresentationcontroller

我使用自定义UIPresentationController与我自己的动画一起执行续集。在prepareForSegue:

myDestinationController.transitioningDelegate = DBViewControllerTransitioningDelegate()
myDestinationController.modalPresentationStyle = .Custom

这是我的DBViewControllerTransitioningDelegate

class DBViewControllerTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {

    func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
        return DBOverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
    }

    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return DBTransitioningAnimator()
    }
}

它不起作用,因为没有调用方法。但是当我设置:

myDestinationController.transitioningDelegate = self

在我的self控制器中添加来自DBViewControllerTransitioningDelegate的2个方法一切正常。这两种方法都被称为。为什么?有什么区别?

1 个答案:

答案 0 :(得分:3)

  

transitioningDelegateUIViewController的声明:

     

weak var transitioningDelegate: UIViewControllerTransitioningDelegate?

您可以看到transitioningDelegate持有weak引用。自定义TransitioningDelegate实例在您创建后立即发布,因为此处没有人拥有所有权。当您在“控制器”中采用委托并将其分配给transitioningDelegate时,某人'正在为您保留此委托实例。