0

I've been trying to add a blur effect to my app and upon debugging it using breakpoints, the UIBlurEffect variable is always nil.

Following is the code I am using:

UIBlurEffect *effect = [[UIBlurEffect alloc] init];
effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect: effect];
bluredView.frame = self.view.bounds;
[self.view addSubview:bluredView];

I have tried a couple different things, for example instead of alloc and init UIBlurEffect, directly using it as follows:

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

It is still always set to nil. Is there an import I'm missing? I have imported UIKit in my .h file but 'effect' is always nil for some reason.

If anyone has experience the same, I would really appreciate it if you could share your experience.

Any help on the matter would be great! Thanks in advance!

Aashay
  • 383
  • 1
  • 3
  • 10
  • Did you assume it is nil, because you cannot see it or how do you detect it? – Simon Degn Jul 13 '15 at 23:46
  • Sorry, I guess I should've mentioned this more clearly. I set the breakpoint at the line: [self.view addSubview:bluredView]; and saw that bluredView was nil. So I set a breakpoint at: UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect: effect]; and saw that effect was nil – Aashay Jul 14 '15 at 00:57
  • Set the breakpoint at a line under the actual line. The break point stops the code before running the line it's on which means that the `UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect: effect];` isn't declared when you test the value. Set the breakpoint below and hold your mouse over the line you want to check. – Simon Degn Jul 14 '15 at 02:22

2 Answers2

0

Are you running on iOS 7? UIBlurEffect is only available on iOS 8 and above.

Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39
0

These two Gits may help you, even I firstly didn't see they use UIBlurImage. Try them :)

LBBlurredImage

BTGlassScrollView

BlueBookBi.
  • 39
  • 2
  • 9
  • Thank you for your response. I will check the Gits out. In my current case, as @EwamMellor pointed out, the devices it was showing nil on is running iOS. – Aashay Jul 14 '15 at 09:40