Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change effect on UIVisualEffectView

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

like image 794
Urkman Avatar asked Jan 22 '15 16:01

Urkman


1 Answers

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)
})
like image 104
Heps Avatar answered Oct 16 '22 19:10

Heps