这就是我现在所做的:
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)
}
}
但它不起作用。为什么?