TableView with image background and blur effect - swift

时间:2015-07-28 23:51:11

标签: ios swift uitableview blur uiblureffect

I have a little problem: I'd like to set an image to background in a TableViewController. I tried this:

MyClass exampleClass;

public Game1() : base()
{
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";

    exampleClass = new MyClass(); //The class is instantiated here
}

Then I give the blur effect to the view, like this:

class SquadreController: UITableViewController {

    override func viewDidLoad()
    {
        super.viewDidLoad()

        var sfondo = UIImage(named: "sfondo")
        self.view.backgroundColor = UIColor(patternImage: sfondo!)

    }

But there is a big problem. I'm working in a TableView and the TableView, TableCell, NavigationItem, etc. have all disappeared after I apply the blur. Can someone help me?

Thanks a lot!

3 个答案:

答案 0 :(得分:8)

Try using a = num_of_lines( ifs ); instead of view.insertSubView(blurView, atIndex: 0)

答案 1 :(得分: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

答案 2 :(得分:0)

这个问题是一个较老的问题,Epic Defeater的回应确实在某种程度上起作用,有一种更好的方法来实现这一目标。您需要覆盖背景视图,而不是添加blurView。具体而言,您需要覆盖tableView.backgroundView

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

仅当您将背景颜色设置为清除时,此功能才有效。