UIBlurEffect在我的UIView上没有按预期工作

时间:2015-05-21 20:10:32

标签: swift uiview uivisualeffectview

我有一个UIView,我在viewDidLoad设置了它的框架。然后我使用blurBackgroundForView函数来模糊它:

override func viewDidLoad() {
  super.viewDidLoad()
  view.frame = CGRectMake(0, superView.frame.maxY-height, superView.frame.width, height)
  // The view is supposed to peak in from the bottom 
  AnimationHelper.blurBackgroundForView(view)
}

static func blurBackgroundForView(view: UIView!){
  view.backgroundColor = .clearColor()
  let blurEffect = UIBlurEffect(style: .Light)
  let blurEffectView = UIVisualEffectView(effect: blurEffect)
  blurEffectView.frame = view.frame
  view.insertSubview(blurEffectView, atIndex: 0)
  }
}

问题是UIView的背景是模糊。 当我将blurBackgroundView(view)的函数调用移到view.frame = ...之上时 我看到一个模糊的视图,但模糊的视图要大得多。

1 个答案:

答案 0 :(得分:1)

blurEffectView的框架应为CGRectMake(0,0,superview.frame.width,height)