1
votes

I have a UIVisualEffectView created in IB and a property

@IBOutlet weak var visualEffectStack: UIVisualEffectView!

I can show and hide the visual effect view using

visualEffectStack.isHidden = false
visualEffectStack.isHidden = true

or using alpha.

I want to animate appearance of the view, but it does not animate.

visualEffectStack.alpha = 0
visualEffectStack.isHidden = false

UIView.animate(withDuration: 0.5, delay: 0.5, options: [.curveEaseIn, .beginFromCurrentState], animations: {
        self.visualEffectStack.alpha = 1
    })

Is there a problem in my code or is it the visual effect view?

Swift 3.1 and iOS 10

1
try opacity instead of alphaKhalid Afridi
Just tested your code its working as expected.What you mean not animating. you should considered changing your animation duration to higher value(duration or delay 0.5 is too quick if you using above code in viewDidLoad).Joe
@Joe Thanks for testing it out. When I create simple project with nothing else, it also works for me. I am adding details (custom views, rounded corners etc.) to get closer to the real world project and trying to find what is causing this.MirekE
@MirekE where are you calling your animation?Tushar Sharma
@TusharSharma On a button click.MirekE

1 Answers

0
votes

After doing some more research I found that the UIVisualEffectView should be always kept with alpha = 1. So animating alpha or isHidden should never be done.

From Apple's documentation:

Setting the Correct Alpha Value

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.