[英]UIBlurEffect in a custom modal presentation
我目前正在使用自定义UIPresentationController
在屏幕的三分之一处呈现视图控制器。 在我UIPresentationController
,我包裹presentedViewController
的一些看法得到圆角(在苹果的自定义转换的示例应用程序等)的影子。 我最近增加了一个UIVisualEffectView
用UIBlurEffect
到presentedViewController
等级,但它显示的是怪异。 视图现在是半透明的,但不模糊。
我认为这是因为模糊效果正确应用,但因为它是一个模态演示,它不会看到背后的视图,因此无法模糊它。 有什么想法吗? 这是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)
正如我在上面的评论中所说的,根据我的经验,使用UIPresentationController
的presentationStyle
属性可以定义一旦发生后如何处理所呈现的视图。 在这里查看更多关于它的信息。 属性本身是UIModalPresentationStyle
类型,你可以在这里看到它的可用值。
在我看来,似乎overCurrentContext
它是你想要的价值。 来自Apple的文档:
演示文稿完成后,不会从视图层次结构中删除所显示内容下方的视图。 因此,如果呈现的视图控制器没有用不透明的内容填充屏幕,则底层内容会显示出来。
在我看来,这意味着您的模糊视图将有一些模糊的东西。
此外,即使Apple的文档似乎没有,你也可以试试这个 。 我认为属性的默认值是true
不false
在那里提到。
我假设你在模拟器上测试它,对吗? 如果是这样,请务必检查模拟器的图形质量覆盖设置并将其设置为高质量。 这应该为你做的伎俩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.