Change effect to UIVisualEffectView

Is there a way to change the effect on a UIVisualEffectView? In my application, I create a UIVisualEffectView in Storyboards, and then I want to change it to Light or Dark to userettings ...

I see only "initWithEffect", and the "effect" property is read-only: (

So, any idea on how to solve this problem?

Thanks Urkman

+5
source share
2 answers

In fact, there is now the opportunity to do it!

myVisualEffectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 

You can animate it!

 [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 the style to nil to gradually remove the blur effect.

+6
source

Unfortunately, you cannot change the viewing effect after creating it.

So, if you use UIVisualEffectsView as a container for searching, you will need to replace the effects view with a new one created using another effect, and move your hierarchy into a new container.

If you use UIVisualEffectsView to blur all views behind it, you can, for example, create both blurry views in your storyboard, set one of them to hidden, and change their hidden states in accordance with user settings.

0
source

Source: https://habr.com/ru/post/1211713/


All Articles