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

标签 ios swift uicollectionview uikit

我尝试在我的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

enter image description here

最佳答案

UIRefreshControl无需设置frame

我通常使用以下步骤来实现它:

在类属性 block 中:

let refreshControl: UIRefreshControl = UIRefreshControl()

viewDidLoad中:

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

类主体中的某处:

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

希望有帮助。

附注有时会出现刷新控制闪烁错误(某种程度上与您的类似)。可以通过在 viewDidLoad() 方法中添加 extendedLayoutInincludesOpaqueBars = true 来解决。

关于iOS UICollectionView 推送刷新时出现意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53084506/

相关文章:

ios - 通过应用过滤从 ALAsset 获取缩略图的快速方法

ios - 如何删除单元格开头和文本之间的空格?

ios - 从 xib 文件动态加载 iOS View

ios - 使collectionviewcell出队的奇怪错误

ios - 带 UIRefreshControl 的水平 UICollectionView

ios - 带有包装标签的静态表格单元格的动态高度?

swift - 快速更改 backButtonItem 的标题

ios - 后台播种/加载 iOS 核心数据存储

ios - UITableViewCell 无法根据它包含的动态 CollectionView 调整高度

ios - Coreplot 绘图空间范围 - iOS