【发布时间】:2018-11-02 17:19:20
【问题描述】:
我的目标是用 Lottie 动画替换 UIRefreshControl 的默认微调器。
我的问题是当我拉下我的子视图为UIRefreshControl 的UICollectionView 时动画不会立即播放。动画仅在我稍微向下滚动并暂停手指时播放。当我再次开始移动滚动位置时,它会立即回到初始状态,不播放。
任何指导将不胜感激,以下是相关代码..
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
}
}
}
【问题讨论】:
标签: ios swift uicollectionview uirefreshcontrol lottie