我使用自定义的uipresentationcontroller用自己的动画来执行续集。在prepareForSegue:
myDestinationController.transitioningDelegate = DBViewControllerTransitioningDelegate()
myDestinationController.modalPresentationStyle = .Custom
这是我的:
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
在My
DBViewControllerTransitioningDelegate
控制器中添加两个Myself
方法,一切都很好。这两种方法被调用。为什么?有什么区别? 最佳答案
transitioningDelegate
中UIViewController
的声明:weak var transitioningDelegate: UIViewControllerTransitioningDelegate?
如您所见,持有transitioningDelegate
引用。自定义TransitioningDelegate实例在您创建后立即被释放,因为这里没有人拥有所有权。当您在“控制器”中采用委托并将其分配给“某人”时,将为您保留此委托实例。
关于swift - 当分离到从NSObject继承的自定义类时,TransitioningDelegate对UIPresentationController不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31109704/