将 Activity 指示器设置为 CollectionViewCell
Setting Activity Indicator to CollectionViewCell
我正在尝试为每个集合视图单元格显示 activity 初始加载时间指示器。我尝试将它放在 cellForItemAtIndexPath
中,但是由于某种原因,它被创建在单元格上方 20 像素处。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("AACollectionViewCell", forIndexPath: indexPath) as! AACollectionViewCell
let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
activityView.center = cell.theImage.center
// Also tried
activityView.center = cell.contentView.center
activityView.startAnimating()
return cell
}
正确的处理方式是什么?
编辑:我也试过了,但它没有在任何地方创建activity指标
let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
activityView.center = cell.contentView.center
cell.contentView.addSubview(activityView)
cell.contentView.center
从其父视图的坐标系中为您提供 contentView
的框架。你应该做什么:
activityView.center = CGPointMake(cell.contentView.frame.size.width / 2, cell.contentView.frame.size.height / 2)
我正在尝试为每个集合视图单元格显示 activity 初始加载时间指示器。我尝试将它放在 cellForItemAtIndexPath
中,但是由于某种原因,它被创建在单元格上方 20 像素处。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("AACollectionViewCell", forIndexPath: indexPath) as! AACollectionViewCell
let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
activityView.center = cell.theImage.center
// Also tried
activityView.center = cell.contentView.center
activityView.startAnimating()
return cell
}
正确的处理方式是什么?
编辑:我也试过了,但它没有在任何地方创建activity指标
let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
activityView.center = cell.contentView.center
cell.contentView.addSubview(activityView)
cell.contentView.center
从其父视图的坐标系中为您提供 contentView
的框架。你应该做什么:
activityView.center = CGPointMake(cell.contentView.frame.size.width / 2, cell.contentView.frame.size.height / 2)