Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode warning: "This will cause the effect to appear broken until opacity returns to 1"

I have a prototype cell and I put a UIVisualEffectView inside its ContentView. Visual Effect View's Blur Style is Dark and Vibrancy is off. Then I set the alpha of the Visual Effect View to 0,5 using the IB.

Then on runtime, I get a warning that says:

<UIVisualEffectView ...> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.

I couldn't understand why this warning is there and how I can set this alpha property properly.

like image 602
aslisabanci Avatar asked Oct 12 '14 12:10

aslisabanci


5 Answers

The question is what do you want to animate. If it's the effect, you cannot animate it via the alpha property. However, since iOS 9, you can animate it with setting the effect in animation block.

UIVisualEffectView* view = [[UIVisualEffectView alloc] initWithFrame:self.view.bounds];
view.effect = nil;
[UIView animateWithDuration:0.3 animations:^{
    view.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}];

Alternatively, you can animate the effect by animating the alpha of the wrapper view, as proposed in the other answers (working even on iOS 8).

If you want to animate the content of the visual effect view (the subviews), animate the contentView property instead (which you should use to add subviews of the effect view).

[UIView animateWithDuration:0.3 animations:^{
    view.contentView.alpha = 1.0;
}];

So to sum up, you should never change alpha of the UIVisualEffectView itself as it's most likely not what you want.

like image 112
zvonicek Avatar answered Oct 06 '22 18:10

zvonicek


As far as I can remember you cannot change the alpha of a visual effect view. The alpha always has to be one.

like image 45
user1179321 Avatar answered Oct 06 '22 19:10

user1179321


The desired effect can be achieved by setting alpha of the background color rather than the Visual Effect View. The subviews should be added to View of Visual Effect View and they are not affected by the background blur.

The Vibrancy effect must be selected in View Effect View options above.

See image:

enter image description here

like image 30
Sahil Kapoor Avatar answered Oct 06 '22 18:10

Sahil Kapoor


user1179321 definetely right. According to UIVisualEffectView Documentation;

When using the UIVisualEffectView class, avoid alpha values that are less than 1. Creating views that are partially transparent causes the system to combine the view and all the associated subviews during an offscreen render pass. UIVisualEffectView objects need to be combined as part of the content they are layered on top of in order to look correct. Setting the alpha to less than 1 on the visual effect view or any of its superviews causes many effects to look incorrect or not show up at all.

https://developer.apple.com/library/ios/documentation/uikit/reference/UIVisualEffectView/index.html

like image 39
Kemal Can Kaynak Avatar answered Oct 06 '22 19:10

Kemal Can Kaynak


My solution:

  1. Duplicate the layer behind the visual effect view. (In my case an UIImageView)
  2. Animates the alpha value the the duplicated view. (e.g. alpha form 1 to 0, shows the blurred Image)
like image 30
Bill Chan Avatar answered Oct 06 '22 19:10

Bill Chan