-2

I'm trying to add a blur effect to a background view.

Here's my background view. https://github.com/martinjuhasz/MJPopupViewController/blob/master/Source/MJPopupBackgroundView.m

I believe that the idea is to take a snapshot of the parent view and then add a blur effect to that image.

I've seen various approaches not sure what will work and what is the best approach.

Also I'm not sure where I'd create the snapshot.

Jules
  • 7,568
  • 14
  • 102
  • 186
  • 1
    possible duplicate of [iOS 7 style Blur view](http://stackoverflow.com/questions/17036655/ios-7-style-blur-view) – David Berry Apr 17 '14 at 21:30

2 Answers2

1

The most common way is indeed probably just to take a snapshot and blur that.

You can take a snapshot by doing something like this:

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0f);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
    UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return snapshotImage;
}

Keep in mind this is a fast iOS7+ blurring method so if you want to support lower versions of iOS you will need to use a slower method, detailed in this answer.

There are a lot of ways to achieve blur, the 2 most popular are probably to use Apple's UIImageEffects WWDC sample code which can be found here, or to use GPUImage, which can be found here.

Community
  • 1
  • 1
Dima
  • 23,484
  • 6
  • 56
  • 83
  • Thanks, where would I put / call that function? – Jules Apr 17 '14 at 21:47
  • You can put it wherever you want (most likely place would be a `UIImage` category). You call it when you want to get a snapshot of some view (probably when you are about to put an overlay on top of it). – Dima Apr 17 '14 at 21:51
0

Ablow link points to present view and affect the background with blur effect

https://stackoverflow.com/a/52374977/5233180

Magdy Zamel
  • 470
  • 5
  • 17
  • This seems like more of a comment than an answer, or possibly a duplicate flag for the question you linked – chevybow Sep 17 '18 at 20:46
  • Thank you for advice, but I haven't enough reputation to add a comment now when I have it I will make it as a comment after I have it – Magdy Zamel Sep 18 '18 at 12:33