简体   繁体   English

iOS UICollectionView推送刷新时出现意外行为

[英]iOS UICollectionView Unexpected behavior on push to refresh

I'm try to implement push to refresh on my collectionView, the code is it. 我正在尝试对我的collectionView实施推送刷新,代码就是它。

private lazy var refreshControl : UIRefreshControl = {
    let frame = CGRect(x: 0, y: 0, width: 30, height: 30)
    let control = UIRefreshControl(frame: frame)
    control.addTarget(self, action: #selector(getAllJobs), for: .valueChanged)
    return control
}()

collectionView.refreshControl = refreshControl

在此处输入图片说明

There is no need to set frame for UIRefreshControl 无需为UIRefreshControl设置框架

I usually implement it using the following steps: 我通常使用以下步骤实现它:

In class properties block: 在类属性块中:

let refreshControl: UIRefreshControl = UIRefreshControl()

In viewDidLoad : viewDidLoad

collectionView.alwaysBounceVertical = true
collectionView.refreshControl = refreshControl
refreshControl.addTarget(self, action: #selector(loadData), for: .valueChanged)

Somewhere in class body: 在课堂上的某个地方:

// Refresh handler
@objc func loadData() {
        // Your refresh-code here
}

Hope it helps. 希望能帮助到你。

PS Sometimes there is refresh control flicker bug (somehow similar to yours). PS有时会有刷新控制闪烁错误(某种程度上类似于您的错误)。 It can be solved by adding: extendedLayoutIncludesOpaqueBars = true to your viewDidLoad() method. 可以通过在viewDidLoad()方法中添加: extendedLayoutIncludesOpaqueBars = true来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM