nothappybob
nothappybob

Reputation: 3107

iOS animate a blur for a view

I would like to quickly animate a blur on a UIView to use as a transition in my app. I'm having trouble knowing where to start. I believe core image is the proper tool for the job. Can anyone point me to a sample of how to blur a UIView? I'm assuming I will need to convert the view into a single UIImage, but I don't know where to proceed from there.

Thanks in advance!

Upvotes: 2

Views: 8107

Answers (3)

kenshin03
kenshin03

Reputation: 103

I recently did some tests with blurring a series of images at different blur settings and animating them simply with UIImageView. You might want to take a look:

AnimatedGaussianBlur

Upvotes: 3

Aurelien Cobb
Aurelien Cobb

Reputation: 435

Taking a snapshot of the View and using GPUImage from Brad Larson (the GPUImageGaussianBlurFilter) got me some nice results.

To animate the view I created a ImageView with the blurred image and animated the alpha channel from 0 to 1 to make the blur appear progressively.

Alternatively, I presume its possible to increase the blursize per frame.

#import "GPUImage.h"
...
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
...
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
...
GPUImageGaussianBlurFilter * filter = [[GPUImageGaussianBlurFilter alloc] init];
filter.blurSize = 0.5;
UIImage * blurred = [filter imageByFilteringImage:image];

Upvotes: 9

Asif Mujteba
Asif Mujteba

Reputation: 4656

rasterizeScale of a uiview's layer is what you need, Here is the code for adding blur effect to UIVIew:

CALayer *layer = [self.blurView layer];
[layer setRasterizationScale:0.3];
[layer setShouldRasterize:YES];

For details refer to Apple Documentation of CALayer, Also this tutorial might help You, hope that helps

Upvotes: 4

Related Questions