我使用自定义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个方法一切正常。这两种方法都被称为。为什么?有什么区别?
答案 0 :(得分:3)
transitioningDelegate
中UIViewController
的声明:
weak var transitioningDelegate: UIViewControllerTransitioningDelegate?
您可以看到transitioningDelegate
持有weak
引用。自定义TransitioningDelegate实例在您创建后立即发布,因为此处没有人拥有所有权。当您在“控制器”中采用委托并将其分配给transitioningDelegate
时,某人'正在为您保留此委托实例。