单击按钮后,我希望能够在将叠加子视图添加到超视图时使用模糊和活力视觉效果遮盖背景(UITableViewController)。通常,我会将视觉效果拖放到Main.storyboard中,但是,我无法将效果拖到表视图上。任何帮助将不胜感激
提前致谢!
答案 0 :(得分:3)
您可以按以下方式在主视图上添加模糊视图
@IBAction func addBlur(_ sender: Any) {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)
}
行中的更多内容
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
您可以添加以下效果
extraLight
light
dark
regular //10.0 or higher
prominent //10.0 or higher
您还可以使用this开源库以获得更大的灵活性
答案 1 :(得分:1)
以编程方式添加效果,这是一段代码片段
var darkBlur:UIBlurEffect = UIBlurEffect()
darkBlur = UIBlurEffect(style: UIBlurEffectStyle.light) //extraLight, light, dark
let blurView = UIVisualEffectView(effect: darkBlur)
blurView.frame = self.view.frame //your view that have any objects
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.yourUIViewToBlur.addSubview(blurView)