自定义模式演示文稿中的UIBlurEffect

jja*_*tie 7 ios swift uimodalpresentationcustom uivisualeffectview

我目前正在使用自定义屏幕的三分之一呈现视图控制器UIPresentationController.在我看来UIPresentationController,我presentedViewController在几个视图中包含圆角和阴影(就像在Apple的Custom Transitions示例应用程序中).我最近添加了一个UIVisualEffectView带有a UIBlurEffectpresentedViewController层次结构,但它显示很奇怪.视图现在是半透明的,但不模糊.

我认为这是因为模糊效果正确应用,但因为它是一个模态演示,它不会看到背后的视图,因此无法模糊它.有什么想法吗?这是相关的代码 override func presentationTransitionWillBegin()

    // Wrap the presented view controller's view in an intermediate hierarchy
    // that applies a shadow and rounded corners to the top-left and top-right
    // edges.  The final effect is built using three intermediate views.
    //
    // presentationWrapperView              <- shadow
    //   |- presentationRoundedCornerView   <- rounded corners (masksToBounds)
    //        |- presentedViewControllerWrapperView
    //             |- presentedViewControllerView (presentedViewController.view)
    //
    // SEE ALSO: The note in AAPLCustomPresentationSecondViewController.m.


    let presentationWrapperView = UIView(frame: frameOfPresentedViewInContainerView)
    presentationWrapperView.layer.shadowOpacity = 0.44
    presentationWrapperView.layer.shadowRadius = 13
    presentationWrapperView.layer.shadowOffset = CGSize(width: 0, height: -6)
    self.presentationWrappingView = presentationWrapperView

    // presentationRoundedCornerView is CORNER_RADIUS points taller than the
    // height of the presented view controller's view.  This is because
    // the cornerRadius is applied to all corners of the view.  Since the
    // effect calls for only the top two corners to be rounded we size
    // the view such that the bottom CORNER_RADIUS points lie below
    // the bottom edge of the screen.
    let presentationRoundedCornerView = UIView(frame: UIEdgeInsetsInsetRect(presentationWrapperView.bounds, UIEdgeInsets(top: 0, left: 0, bottom: -CORNER_RADIUS, right: 0)))
    presentationRoundedCornerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    presentationRoundedCornerView.layer.cornerRadius = CORNER_RADIUS
    presentationRoundedCornerView.layer.masksToBounds = true

    // To undo the extra height added to presentationRoundedCornerView,
    // presentedViewControllerWrapperView is inset by CORNER_RADIUS points.
    // This also matches the size of presentedViewControllerWrapperView's
    // bounds to the size of -frameOfPresentedViewInContainerView.
    let presentedViewControllerWrapperView = UIView(frame: UIEdgeInsetsInsetRect(presentationRoundedCornerView.bounds, UIEdgeInsets(top: 0, left: 0, bottom: CORNER_RADIUS, right: 0)))
    presentedViewControllerWrapperView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

    let blurWrapperView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
    blurWrapperView.autoresizingMask =  [.flexibleWidth, .flexibleHeight]
    blurWrapperView.frame = presentedViewControllerWrapperView.bounds

    // Add presentedViewControllerView -> presentedViewControllerWrapperView.
    presentedViewControllerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    presentedViewControllerView.frame = blurWrapperView.bounds
    blurWrapperView.contentView.addSubview(presentedViewControllerView)

    presentedViewControllerWrapperView.addSubview(blurWrapperView)
    // Add presentedViewControllerWrapperView -> presentationRoundedCornerView.
    presentationRoundedCornerView.addSubview(presentedViewControllerWrapperView)

    // Add presentationRoundedCornerView -> presentationWrapperView.
    presentationWrapperView.addSubview(presentationRoundedCornerView)
Run Code Online (Sandbox Code Playgroud)

Mih*_*atu 2

正如我在上面的评论中所说,根据我的经验,使用 的presentationStyle属性UIPresentationController可以让您定义一旦发生这种情况,如何处理所呈现的视图背后的视图。请参阅此处有关它的更多信息。该属性本身是类型,您可以在此处UIModalPresentationStyle查看它的可用值。

在我看来,这似乎就是overCurrentContext你想要的价值。来自苹果的文档:

当演示结束时,所演示内容下方的视图不会从视图层次结构中删除。因此,如果呈现的视图控制器没有用不透明内容填充屏幕,则底层内容会显示出来。

在我看来,这意味着你的模糊视图将会有一些东西被模糊。

更新


另外,你也可以尝试这个,即使苹果的文档似乎不正确。我认为该属性的默认值并不truefalse其中提到的那样。