0

I have set a background image for my UITableViewController and then added a blur effect with the following code:

 var blur = UIBlurEffect(style: UIBlurEffectStyle.Dark)
 var blurView = UIVisualEffectView(effect: blur)
 blurView.frame = self.view.bounds
 self.view.insertSubview(blurView, atIndex: 0)

When I scroll down, the background image is still there but the blur effect is only there for the first few cells that fit into the view at a time. How can I make it so the blur effect is there as I scroll?

I tried adding the blur effect to each cell, but that makes it look really weird.

shaydawg
  • 1,193
  • 1
  • 12
  • 17

1 Answers1

0

For UITableViewControllers self.view is the UITableView it self. That means any subview you add to self.view will scroll along with the content of the table view.

You could either make an own UIViewController, set up UITableView manually and place it in front of the blur view (instead of placing the blur view inside the table view) or you could move the blur view's location when the table view is scrolled.

To move the blur view to compensate for the table view's offset you can do something like this:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    var blurViewFrame = CGRect()
    blurViewFrame.size = view.bounds.size
    blurViewFrame.y = tableView.contentOffset.y
    blurView.frame = blurViewFrame
}
fluidsonic
  • 4,655
  • 2
  • 24
  • 34