Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBlurEffect not blurring on device but works in simulator

I'm trying to make a UIView with a UIVisualEffectView subview with a UIBlurEffect as the effect. The view is created off the side of the screen and then is slid in using an animation.

Everything works just fine on the simulator (I've tested on an iPhone 4S and an iPhone 6) however on my phone (iPhone 6) the blur just isn't blurring, it looks more like a dark grey with an alpha of 0.5. In addition, when I take a screenshot of the device or open it up from the home screen, the blur is rendered for that single frame before consistent rendering starts again.

Here's a screenshot of the view as it is at the moment: enter image description here

However on the device the blur isn't there, it's essentially just a dark, transparent view.

Here's the code I use to initialise the view, the blurView and vibrancyView properties are declared as global variables:

init(left: Bool){
    self.left = left
    let screenSize = UIScreen.mainScreen().bounds.size

    var rect: CGRect
    if left{
        rect = CGRectMake(-screenSize.width*0.3, 0, screenSize.width*0.3, screenSize.height)
    }else{
        rect = CGRectMake(screenSize.width, 0, screenSize.width*0.3, screenSize.height)
    }

    super.init(frame: rect)
    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
    blurView = UIVisualEffectView(effect: blurEffect)
    blurView.frame = CGRectMake(0, 0, self.frame.width, self.frame.height)
    self.addSubview(blurView)
    let vibrancy = UIVibrancyEffect(forBlurEffect: blurEffect)
    vibrancyView = UIVisualEffectView(effect: vibrancy)
    vibrancyView.frame = blurView.frame
    blurView.addSubview(vibrancyView)

    self.userInteractionEnabled = true
}

And to move the superView, that contains the blurView, in:

func moveIn(){
    UIView.animateWithDuration(0.3, animations: { () -> Void in
        var center = self.center
        if self.left{
            center.x = UIScreen.mainScreen().bounds.size.width*0.15
        }else{
            center.x = UIScreen.mainScreen().bounds.size.width*0.85
        }
        self.center = center
    })
}

As I said before the animation and such works fine but the blurView doesn't blur.

I'm not sure what's going on with this, it makes me think it's something to do with rendering frames but I'm no guru so if anyone has any ideas I'd be more than grateful.

like image 643
Andy Heard Avatar asked Oct 19 '22 18:10

Andy Heard


1 Answers

To close this out, it's because I'm using SpriteKit for the majority of the app, and therefore using SKView and not UIView. I realise I didn't mention this in the question but I wasn't aware that it would be an issue. Apparently an SKView follows a different rendering path and therefore will not get blurred, the suggested method is an effectnode.

like image 71
Andy Heard Avatar answered Oct 22 '22 12:10

Andy Heard