Last active
May 24, 2019 15:10
-
-
Save n00neimp0rtant/27829d87118d984232a4 to your computer and use it in GitHub Desktop.
UIVisualEffectView blur radius manipulation (new for iOS 9)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
how are you doing this if .effect is a read only property?
Its not since iOS9
Excellent tip, thanks!
Not working on iOS 10 anymore unfortunately
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
Implemented this idea in pod: https://github.com/ML-Works/Bluuur