Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Packetfahrer/e4af21b6638a02132176 to your computer and use it in GitHub Desktop.
Save Packetfahrer/e4af21b6638a02132176 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
@k06a
Copy link

k06a commented Jan 21, 2016

Effect resets when app goes to background and restores foreground

@puelocesar
Copy link

It seems that it doesn't work on ios 9.3 anymore..

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