UIBlurEffect在自定义模态演示文稿中

我目前正在用自定义的UIPresentationController在屏幕的三分之一处呈现视图控制器。 在我UIPresentationController ,我包裹presentedViewController的一些看法得到圆角(在苹果的自定义转换的示例应用程序等)的影子。 我最近添加了UIVisualEffectViewUIBlurEffectpresentedViewController UIBlurEffect层次结构,但它显示很奇怪。 该视图现在是半透明的,但没有模糊。

我认为这是因为模糊效果正在被正确应用,但是因为它是一种模式表示,所以它没有看到背后的视图,因此无法模糊它。 有什么想法吗? 以下是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)

正如我在上面的评论中所说的,根据我的经验,使用UIPresentationControllerpresentationStyle属性可以让您定义一旦发生的情况下处理呈现的视图背后的视图的方式。 在这里看到更多关于它的信息。 属性本身是UIModalPresentationStyle类型的,你可以在这里看到它的可用值。

在我看来,它似乎overCurrentContext这是你想要的价值。 从Apple的文档:

演示完成后,呈现内容下的视图不会从视图层次结构中删除。 因此,如果呈现的视图控制器没有在屏幕上填充不透明的内容,底层内容就会显示出来。

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

更新


此外,即使Apple的文档似乎已关闭,您也可以尝试此操作。 我认为该属性的默认值是true而不是像在那里提到的那样是false


我假设你正在模拟器上测试这个,对吧? 如果是这样,确保检查模拟器的图形质量覆盖设置并将其设置为高质量。 这应该为你做的伎俩。

链接地址: http://www.djcxy.com/p/35721.html

上一篇: UIBlurEffect in a custom modal presentation

下一篇: Application Exit Collection was modified; enumeration operation may not execute