我正在尝试为每个集合视图单元格显示初始加载时间的活动指示器。我尝试将其放在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
}
处理它的正确方法是什么?
编辑:我也试过了,但它没有在任何地方创建activityIndicator
let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
activityView.center = cell.contentView.center
cell.contentView.addSubview(activityView)
答案 0 :(得分:4)
cell.contentView.center
从超视图的坐标系中为您提供contentView
的帧。你应该做什么:
activityView.center = CGPointMake(cell.contentView.frame.size.width / 2, cell.contentView.frame.size.height / 2)