ios - 如何在 UIStoryboardSegue 中实现 UIViewControllerTransitioningDelegate?

标签 ios swift uistoryboardsegue uipresentationcontroller

这就是我现在做的:

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: 从 Storyboard 中获取 Controller 。 Controller 以正确的方式呈现:

enter image description here

但我需要通过自定义 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)

关于ios - 如何在 UIStoryboardSegue 中实现 UIViewControllerTransitioningDelegate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38631422/

相关文章:

ios - 调度同步的目的是什么?

ios - 快速拍摄黑色图像

Swift:如何从动态单元捕获开关的修改

ios - 使用 collectionviewCell 使用 override func prepare 传递数据

ios - UILabel 的动画文本更改

ios - 在 Swift 中使用嵌套 reduce

ios - popToViewController 不工作 "Tried to pop to a view controller that doesn' t 存在”

ios - 如何在 Xcode + Swift 4 中制作自定义 UIBarButtonItem 类?

ios - 如何创建两个自定义 Segue,每个方向一个?

ios:根据前一个 View 中使用的segue,与另一个 View 不同的segue