I have a bottom fade-out gradient layer on UITextView
. I'm deleting this fade-out when user reaches the bottom of UIScrollView
. However, when user started to scroll to top, I set it again.
My Problem is that I want to delete this CAGradientLayer
with alpha animation not just directly remove it.
Now I'm removing and setting it with (without animation):
func scrollViewDidScroll(_ scrollView: UIScrollView) {
updateGradientFrame()
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
self.myTextView.layer.mask = nil
}else{
myTextView.layer.mask = gradient
}}
What I tried and doesn't work:
UIView.animate(withDuration: 1) {
self.myTextView.layer.mask = nil
}
Another try (this adds animation to whole UITextView
not just the layer):
let flash = CABasicAnimation(keyPath: "opacity")
flash.fromValue = 1.0
flash.toValue = 0.0
flash.duration = 3.0 // 1 second
flash.autoreverses = false // Back
gradient.add(flash, forKey: "flashAnimation")
What I found on community (Not directly refers to this question):