我有一点问题:我想在TableViewController中将图像设置为背景。我试过这个:
class SquadreController: UITableViewController {
override func viewDidLoad()
{
super.viewDidLoad()
var sfondo = UIImage(named: "sfondo")
self.view.backgroundColor = UIColor(patternImage: sfondo!)
}
然后我给视图赋予模糊效果,如下所示:
let blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
view.addSubview(blurView)
但是有一个大问题。我在Table View中工作,TableView,Table Cell,NavigationItem等在我应用模糊后都消失了。有人能帮我吗?
非常感谢!
尝试使用view.insertSubView(blurView, atIndex: 0)
而不是view.addSubview(blurView) as! UIImageView
我们还可以使用insertSubview在任何其他视图下方或上方添加子视图
//Inserting below your subView
self.view.insertSubview(subview1_name, belowSubview: subview2_name)
//Inserting above your subView
self.view.insertSubview(subview1_name, aboveSubview: subview2_name)
/// You can use any of your view, instead of self.view
这个问题是一个较老的问题,Epic Defeater的回应在某种程度上起作用,有更好的方法来实现这一目标。您需要覆盖背景视图,而不是添加blurView
。具体来说,你需要覆盖tableView.backgroundView
。
let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
tableView.backgroundView = blurView
这仅在您将背景颜色设置为清除时才有效。