UIRefreshControl出现在集合视图项的顶部而不是后面

时间:2017-07-24 10:41:37

标签: ios swift3 uicollectionview uirefreshcontrol

我有一个UICollectionView定期拉动刷新实现,但不知何故,微调器和"拉动刷新"文本显示在集合视图项上方;

如何在物品后面制作?

这是我将UIRefreshControll添加到UICollectionView

的方法
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull down to refresh")
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: UIControlEvents.valueChanged)
collectionView?.refreshControl = refreshControl

2 个答案:

答案 0 :(得分:26)

我解决这个问题的方法是将refreshControll zPosition改为每个视图后面的内容:

refreshControl.layer.zPosition = -1

希望这可以进一步帮助任何人。

答案 1 :(得分:1)

试试这个:

@IBOutlet weak var collectionView: UICollectionView!

var refresher:UIRefreshControl!

override func viewDidLoad() {

   super.viewDidLoad()

    let refresher = UIRefreshControl()
    self.collectionView!.alwaysBounceVertical = true
    self.refresher.tintColor = UIColor.red
    self.refresher.addTarget(self, action: #selector(loadData), for: .valueChanged)
    self.collectionView!.addSubview(refresher)
}

func loadData() {
   //code to execute during refresher
       .
       .
       .
   stopRefresher()         //Call this to stop refresher
 }

func stopRefresher() {
   self.refresher.endRefreshing()
 }