My goal is to replace the default spinner of the UIRefreshControl with a Lottie animation.
My issue is that the animation does not play immediately when I pull down my UICollectionView whose subview is the UIRefreshControl. The animation only plays when I scroll down slightly and pause my finger. The moment I again start moving the scrolling position it immediately goes back to its initial starting state not playing.
Any guidance would be appreciated, below is relevant code..
func setupRefreshControl() {
guard let refreshContents = Bundle.main.loadNibNamed("RefreshControlView", owner: self, options: nil), let refreshView = refreshContents[0] as? RefreshControlView else { return }
refreshView.frame = refreshControl.frame
refreshControl.addSubview(refreshView)
refreshControl.tintColor = UIColor.clear
refreshControl.backgroundColor = UIColor.clear
refreshControl.addTarget(self, action: #selector(exampleFunction), for: .valueChanged)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
for subview in refreshControl.subviews {
if let refreshControlView = subview as? RefreshControlView {
refreshControlView.activityIndicatorControl.animationView.setAnimation(named: "lottieJson")
refreshControlView.activityIndicatorControl.animationView.loopAnimation = true
refreshControlView.activityIndicatorControl.animationView.play()
break
} else {
continue
}
}
}