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 - WKWebView 在打开相机 Swift 时关闭

ios - 在 Swift 中使用 header 发出 HTTP 请求

ios - 来自 UITableView 部分的条件目标 View Controller

ios - 在 UITableView 上选择行时委托(delegate)不起作用

ios - 如何在非ARC模式下手动释放此静态变量

ios - Swift 无法将 JSON 字符串存储为日期

ios - 使用 Interface Builder/Storyboards 中的自动布局创建网格类型布局

ios - 来自 CGImageRef 的 UIImage

ios - 如何在 tableView 之外获取所有自定义 tableview 单元格 textField 和 textView 值

cocoa-touch - push 和 modal segue 的区别