如何在 UIStoryboardSegue 中实现 UIViewControllerTransitioningDelegate?
How to implement UIViewControllerTransitioningDelegate in UIStoryboardSegue?
这就是我现在所做的:
func presentOverlayController(controller: UIViewController) {
controller.modalPresentationStyle = .Custom
controller.transitioningDelegate = self
presentViewController(controller, animated: true, completion: nil)
}
//MARK: - UIViewControllerTransitioningDelegate
public func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return OverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
效果非常棒。首先,我使用 .instantiateViewControllerWithIdentifier:
从情节提要中获取控制器。控制器的正确呈现方式:
但是我需要用我的自定义 segue:
实现相同的结果
class OverlaySegue: UIStoryboardSegue, UIViewControllerTransitioningDelegate {
override func perform() {
destinationViewController.modalPresentationStyle = .Custom
destinationViewController.transitioningDelegate = self
}
//MARK: - UIViewControllerTransitioningDelegate
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return OverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
}
但它不起作用。为什么?
在 perform
结束时,您需要调用 presentViewController(destinationViewController, animated: true, completion: nil)
。
这就是我现在所做的:
func presentOverlayController(controller: UIViewController) {
controller.modalPresentationStyle = .Custom
controller.transitioningDelegate = self
presentViewController(controller, animated: true, completion: nil)
}
//MARK: - UIViewControllerTransitioningDelegate
public func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return OverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
效果非常棒。首先,我使用 .instantiateViewControllerWithIdentifier:
从情节提要中获取控制器。控制器的正确呈现方式:
但是我需要用我的自定义 segue:
实现相同的结果class OverlaySegue: UIStoryboardSegue, UIViewControllerTransitioningDelegate {
override func perform() {
destinationViewController.modalPresentationStyle = .Custom
destinationViewController.transitioningDelegate = self
}
//MARK: - UIViewControllerTransitioningDelegate
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return OverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
}
但它不起作用。为什么?
在 perform
结束时,您需要调用 presentViewController(destinationViewController, animated: true, completion: nil)
。