I have a collection view cell that has a UIVisualEffectView
as a subview. This view initially is at alpha = 0.0
and when the user tap in the cell it becomes alpha = 1.0
.
let blurEffect = UIBlurEffect(style: .light)
blurEffectView.effect = blurEffect
blurEffectView.frame = cardView.bounds
blurEffectView.alpha = 0.0
cardView.addSubview(blurEffectView)
blurEffectView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
I am doing this animating it like the following:
DispatchQueue.main.async {
UIView.animate(withDuration: 0.5) {
cell.blurEffectView.alpha = 1.0
}
}
The issue is that the blur view becomes visible but without any animation. Any idea what I'm doing wrong?
EDIT: Thanks to @TylerTheCompiler answer I have now changed the animation of the alpha for the Blur Effect itself. The issue is that the animation keeps not happening.
I use cell.blurEffectView.fadeInEffect()
in func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
func fadeInEffect(_ style:UIBlurEffect.Style = .light, withDuration duration: TimeInterval = 1.0) {
if #available(iOS 10.0, *) {
let animator = UIViewPropertyAnimator(duration: duration, curve: .easeIn) {
self.effect = UIBlurEffect(style: style)
}
animator.startAnimation()
}else {
// Fallback on earlier versions
UIView.animate(withDuration: duration) {
self.effect = UIBlurEffect(style: style)
}
}
}
Thank you!