I want to an Shimmer animation like this: https://gph.is/g/amWgbvj. (This one created by using library: https://github.com/dvtng/react-loading-skeleton in WebApp)
I tried to use GradientLayer with opacity to create Shimmer animation through all subviews:
gradientLayer.colors = [Colors.tokenDark20.cgColor, Colors.tokenDark10.cgColor, Colors.tokenDark20.cgColor]
gradientLayer.opacity = 0.5
But I got the animation: https://gph.is/g/4L3K01P.
More effort:
I tried to use the library: https://github.com/gonzalonunez/Skeleton, tried to chain animation from left to right, but I cant make the same length of gradient shape for all subview:
extension ShimmerExampleCell: SkeletonOwner {
var gradientLayers: [CAGradientLayer] {
return [imagePlaceholderView.gradientLayer, titlePlaceholderView.gradientLayer, subtitlePlaceholderView.gradientLayer]
}
func slide(to dir: SkeletonDirection, group: ((CAAnimationGroup) -> Void) = { _ in }) {
imagePlaceholderView.gradientLayer.slide(to: .right) { (animationGroup) in
animationGroup.beginTime = 0
}
titlePlaceholderView.gradientLayer.slide(to: .right) { (animationGroup) in
animationGroup.beginTime = 1.1
subtitlePlaceholderView.gradientLayer.add(animationGroup, forKey: CAGradientLayer.kSlidingAnimationKey)
}
}
}
I got the animation in here: https://gph.is/g/ZPgPlXV
am I wrong to approach the way to make the Shimmer animation?
Help me please! Thank you in advance!
You can try to use library SkeletonView; it should help you easily implement shimmer animation wherever you want.