7

我目前在屏幕的三分之一上展示一个视图控制器,带有一个自定义UIPresentationController. 在我的 中UIPresentationController,我将其包裹presentedViewController在几个视图中以获得圆角和阴影(就像在 Apple 的自定义过渡示例应用程序中一样)。我最近在层次结构中添加了UIVisualEffectViewa ,但它显示得很奇怪。视图现在是半透明的,但不是模糊的。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)
4

2 回答 2

3

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

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

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

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

更新


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

于 2017-01-09T21:17:29.450 回答
0

我假设您正在模拟器上进行测试,对吧?如果是这样,请确保检查模拟器的 Graphic's Quality Override 设置并将其设置为 High Quality。那应该对你有用。

于 2018-03-27T15:59:52.597 回答