1

我使用自定义 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控制器中添加 2 种方法,DBViewControllerTransitioningDelegate一切都很好。这两种方法被调用。为什么?有什么区别?

4

1 回答 1

3

声明transitioningDelegatein UIViewController

weak var transitioningDelegate: UIViewControllerTransitioningDelegate?

如您所见transitioningDelegate,持有weak参考。自定义的 TransitioningDelegate 实例在您创建后立即发布,因为这里没有人拥有所有权。当您在“控制器”中采用委托并将其分配给transitioningDelegate“某人”时,将为您保留此委托实例。

于 2015-11-16T10:34:17.297 回答