gpt4 book ai didi

ios - 自定义模式演示中的 UIBlurEffect

转载 作者:搜寻专家 更新时间:2023-10-30 21:58:45 25 4
gpt4 key购买 nike

我目前使用自定义 UIPresentationController 在三分之一的屏幕上显示 View Controller 。在我的 UIPresentationController 中,我将 presentedViewController 包裹在几个 View 中以获得圆角和阴影(就像在 Apple 的 Custom Transitions 示例应用程序中一样)。我最近在 presentedViewController 层次结构中添加了一个带有 UIBlurEffectUIVisualEffectView,但它显示得很奇怪。 View 现在是半透明的,但不模糊。

我认为这是因为模糊效果应用得当,但因为它是模态呈现,所以看不到后面的 View ,因此无法对其进行模糊处理。有什么想法吗?这是相关代码覆盖 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 属性可以让您定义呈现 View 背后的 View 的处理方式一旦发生这种情况。参见 here有关它的更多信息。该属性本身是 UIModalPresentationStyle 类型,您可以看到它的可用值 here .

在我看来,overCurrentContext 似乎就是您想要的值。来自 Apple 的文档:

The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.

在我看来,这意味着您的模糊 View 将变得模糊。

更新


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

关于ios - 自定义模式演示中的 UIBlurEffect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39087710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com