【发布时间】:2017-06-27 14:11:16
【问题描述】:
我是 swift 新手。我不知道我该怎么做。基本上我需要在集合视图加载所有数据时显示 uiactivity 指示器,然后您尝试滚动然后显示 uiactivity 指示器。这意味着从网络加载更多数据,请稍等。
我做了什么。
///define
var indicatorFooter : UIActivityIndicatorView!
//set up UIActivityIndicatorView to the collection view
override func setupViews() {
indicatorFooter = UIActivityIndicatorView(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(collectionView.frame.width), height: CGFloat(44)))
indicatorFooter.color = UIColor.black
collectionView.addSubview(indicatorFooter)
}
//end of the scroll view then load next 20 data from api
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
// UITableView only moves in one direction, y axis
let currentOffset = scrollView.contentOffset.y
let maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height
// Change 10.0 to adjust the distance from bottom
if maximumOffset - currentOffset <= 10.0 {
self.loadMore()
}
}
//request web to down load data
func loadMore(){
//but it is not working indicator
indicatorFooter.startAnimating()
}
【问题讨论】:
标签: ios swift swift3 uicollectionview uiactivityindicatorview