我有一个模态segue (带有Form Sheet演示文稿),只要选择tableViewCell
,我就会调用它。我在故事板中设置了segue,但如果需要,我可以以编程方式设置它。我希望模态视图的背景为Visual Effect View with Blur
而不是半透明的黑色。我怎样才能做到这一点?谢谢您的帮助!我正在使用Swift 3。
答案 0 :(得分: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; 13会议&#34; Custom Transitions Using View Controllers&#34;