Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blur TableView except one Cell

How can you blur the whole view except a single table view cell?

The effect should be similar to the 3D touch blur effect. E.g. Mail app:

Blur effect

like image 609
Lorenz Wöhr Avatar asked Dec 09 '25 02:12

Lorenz Wöhr


1 Answers

  • The effect of blur applies precisely to the whole screen but the selected cell in the case of the mail app. If you only want the effect to apply to your table view, you could maybe put a blur visual view on tope of your each cell's content, and set its effect to nil

    cell.blurView.effect = nil
    

    appart when one cell is selected. To do that, play with the didSelectRow function and reload the data so that at the end you get the effect you want. (you can even animate the change with UIView.animate())

    UIView.animate(withDuration: 0.5, animations: {
         cell.blurView.effect = UIBlurEffect.init(style: .light)
    }
    
  • The problem is that the solution I told you is not very power efficient, but I can think of another one: Consider having two blur view that display no effect when no cell is selected, then you can as soon as the cell is selected, set the two blur view so that the first one takes the whole part of the screen at the TOP of your cell, and the other one covers the BOTTOM.

  • Ok last idea: you could, in the didSelectRow method, add a blurView to the whole screen

    UIApplication.shared.keyWindow?.addSubview(blurView)  
    

    and then add the cell on top of that and of course removing all this when the blur view is tapped for example

Hope it helps ;)

like image 142
Stormsyders Avatar answered Dec 12 '25 03:12

Stormsyders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!