2017-06-20 51 views
0

我有一个模式segue (与表单表示)我打电话时,无论何时tableViewCell被选中。我在故事板中设置了segue,但如果需要的话,我可以通过程序设置它。我希望模态视图的背景是Visual Effect View with Blur而不是半透明的黑色。我怎样才能做到这一点?谢谢您的帮助!我正在使用Swift 3.Modal Segue表单模糊背景

回答

0

您可以通过执行两种协议来实现这一点 - 对于您的Animator,<UIViewControllerAnimatedTransitioning>TransitioningDelegate<UIViewControllerTransitioningDelegate>

Animator,你需要重写方法animateTransition,创造有UIVisualEffectView,您将添加到transitionContext.containerView

class Animator: UIViewControllerAnimatedTransitioning 
{ 
    func blurEffectView(_ transitionContext: UIViewControllerContextTransitioning) -> UIVisualEffectView 
    { 
     let container = transitionContext.containerView; 
     var effectView = objc_getAssociatedObject(container, &BlurEffectViewKey) as? UIVisualEffectView; 
     if effectView == nil 
     { 
      let effect = UIBlurEffect(style: .dark) 

      effectView = UIVisualEffectView(effect: effect); 
      objc_setAssociatedObject(container, &BlurEffectViewKey, effectView!, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN); 
      container.addSubview(effectView!); 
      effectView!.frame = container.bounds; 

     } 
     return effectView!; 
    } 

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) 
    { 
     ... 

     let blurView = self.blurEffectView(transitionContext); 

     if (presenting) 
     { 
      blurView.contentView.addSubview(toController.view); 
     } 

     ... 
    } 

    ... 
} 

然后,设置和展示您的模态控制器:

presentedViewController.transitioningDelegate = myTransitioningDelegate 
presentedViewController.modalPresentationStyle = .overFullScreen 
self.present(presentedViewController, animated:false, completion:nil) 

欲了解更多详细信息,请参阅WWDC'13会议“Custom Transitions Using View Controllers