2016-07-28 32 views
0

这就是我现在做的事:如何在UIStoryboardSegue中实现UIViewControllerTransitioningDelegate?

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:从故事板获取控制器。控制器给出的正确方法:

enter image description here

但同样的结果,我需要实现我的自定义赛格瑞

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

,但它不工作。为什么?

回答

1

perform的结尾处,您需要致电presentViewController(destinationViewController, animated: true, completion: nil)

+1

当然,我怎么能忘记这个? –