Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edwardean/8d3cb9f852879c6413a1e095fefe437b to your computer and use it in GitHub Desktop.
Save edwardean/8d3cb9f852879c6413a1e095fefe437b 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment