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

7

29

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.

Sailboat answered 12/10, 2014 at 12:30 Comment(3)
Fade in/out UIVisualEffectView - https://mcmap.net/q/88603/-how-to-fade-a-uivisualeffectview-and-or-uiblureffect-in-and-outPanel
You can do it with snapshots, and never touch the blur view opacity: https://mcmap.net/q/88603/-how-to-fade-a-uivisualeffectview-and-or-uiblureffect-in-and-outAnaya
Interestingly, I get this even though I'm setting the alpha in a method called from the completion block fro the animation. It seems to me the animation is by definition finished by then. Weird.Lilli
C
12

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

Cribb answered 15/10, 2014 at 12:2 Comment(2)
Sure you can. It might just not give the desired effect. However, in many cases it still will so just see this as a warning.Amazon
Visual Effect's alpha is changeable, but this warning annoying.Ovary
V
14

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.

Veneer answered 15/12, 2015 at 13:55 Comment(0)
C
12

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

Cribb answered 15/10, 2014 at 12:2 Comment(2)
Sure you can. It might just not give the desired effect. However, in many cases it still will so just see this as a warning.Amazon
Visual Effect's alpha is changeable, but this warning annoying.Ovary
M
8

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

Manicurist answered 25/11, 2014 at 10:24 Comment(4)
The style don't appear on XCode 6.1.1Billfish
Please check if the Vibrancy is Checked. I updated the answer :)Manicurist
This result in a different effect isn't it. Since alpha-ing the background will cause the content (if there is any) to still show up at full alpha.Queensland
No it produces exactly what is needed. The use case wants the desired effect without changing alpha of content. You can either add a view to the visual effect view and change it's alpha or change alpha of individual elements if you want to change foreground(content's) transparency.Manicurist
F
5

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

Foxhound answered 24/10, 2014 at 13:12 Comment(1)
How should we change the blur visual effect properly if we want it to be more transparent?Beberg
G
1

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)
Govan answered 27/7, 2015 at 19:38 Comment(0)
U
0

If u presenting viewcontroller modally, try to disable animation checkbox in segue.

Upstretched answered 30/1, 2017 at 11:50 Comment(2)
elaborate your answerMeletius
if u presenting viewcontroller without animation, u can animate your background uivisualeffectview manually.Upstretched
M
0

You never know if the delay is long enough; so a bit of a cleaner solution is to just do the presentation in the next run loop.

 dispatch_async(dispatch_get_main_queue(), ^(void){
    [self presentViewController:yourPopoverr animated: YES completion: nil];
  });
Marquardt answered 24/5, 2017 at 5:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.