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