0

这就是我现在所做的:

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)
    }
}

但它不起作用。为什么?

4

1 回答 1

1

最后perform你需要调用presentViewController(destinationViewController, animated: true, completion: nil).

于 2016-07-28T08:59:37.210 回答