Skip to content

Instantly share code, notes, and snippets.

Last active May 24, 2019 15:10
Show Gist options
  • Save n00neimp0rtant/27829d87118d984232a4 to your computer and use it in GitHub Desktop.
Save n00neimp0rtant/27829d87118d984232a4 to your computer and use it in GitHub Desktop.
UIVisualEffectView blur radius manipulation (new for iOS 9)
// iOS 9 allows you to animate between visual effects, which gives you the
// ability to manipulate the blur radius. this can be useful for animating
// a backdrop for a custom modal, and with a few tricks, can even be set
// indirectly, allowing you to "scrub" between them back and forth with
// a gesture, just like when you pull down Spotlight.
// these are the two effects you want to transition between
UIVisualEffect *startEffect = nil; // "nil" means no blur/tint/vibrancy (plain, fully-transparent view)
UIVisualEffect *endEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:startEffect];
blurView.userInteractionEnabled = NO;
[self.view addSubview:blurView];
// transistion between the effects
[UIView animateWithDuration:1.0 animations:^{
blurView.effect = endEffect;
// or, "freeze" time so it doesn't actually animate...
blurView.layer.speed = 0;
[UIView animateWithDuration:1.0 animations:^{
blurView.effect = endEffect;
// ...then set timeOffset to desired "frozen in time" point of transition, from 0 to 1
blurView.layer.timeOffset = 0.5; // halfway blurred
Copy link

k06a commented Jan 21, 2016

Effect resets when app goes to background and restores foreground

Copy link

k06a commented May 30, 2016

Implemented this idea in pod:

Copy link

BrandDev commented Jun 1, 2016

how are you doing this if .effect is a read only property?

Copy link

Its not since iOS9

Copy link

mvoong commented Jul 16, 2016

Excellent tip, thanks!

Copy link

Not working on iOS 10 anymore unfortunately

Copy link

y25zhao commented Sep 27, 2016

iOS 10 broke a lot of things! Looking for a solution to this now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment