[英]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.