Reputation: 1328
is there a way to change the Effect on a UIVisualEffectView? In my App I create a UIVisualEffectView in Storyboards and then I want to change it toLight or Dark on usersettings...
I only see a "initWithEffect" and the "effect" property is readonly :(
So, any Idea on how to solve this?
Thanks, Urkman
Upvotes: 7
Views: 1981
Reputation: 995
Actually there is now possibility to do that!
myVisualEffectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
You can animate this!
[UIView animateWithDuration:1.0 animations:^{
myVisualEffectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
}];
You can even animate blur add and remove - almost like in Spotlight reaveal on Springboard! Just set style to nil to remove blur effect progressively.
Swift 4 version:
myVisualEffectView.effect = UIBlurEffect(style: .dark)
UIView.animate(withDuration: 1, animations: {
myVisualEffectView.effect = UIBlurEffect(style: .extraLight)
})
Upvotes: 13
Reputation: 229
Unfortunately, you cannot change effect of view once created.
So if you are using UIVisualEffectsView as a container for views hierarcy, you'll need to replace effects view with the new one, created with another effect, and move your hierarchy to the new container.
If you are using UIVisualEffectsView just to blur all the views behind it, you can, for example, create both blurring views in your storyboard, set one of them to hidden and change their hidden states according to user settings.
Upvotes: 1