5

我有一个小问题:我想在 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)

但是有一个大问题。我在 TableView 中工作,TableView、TableCell、NavigationItem 等在我应用模糊后都消失了。有人能帮我吗?

非常感谢!

4

3 回答 3

9

尝试使用view.insertSubView(blurView, atIndex: 0)而不是view.addSubview(blurView) as! UIImageView

于 2015-07-29T00:30:17.270 回答
2

这个问题是一个较老的问题,Epic Defeater 的回答在某种程度上是有效的,有更好的方法来完成这个。而不是添加blurView,您需要覆盖背景视图。具体来说,您需要覆盖tableView.backgroundView.

let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
tableView.backgroundView = blurView

这仅在您将背景颜色设置为清除时才有效。

于 2017-12-15T00:27:50.957 回答
0

我们还可以使用 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
于 2017-03-03T10:45:35.987 回答