ios - iOS UICollectionView 推送刷新时的意外行为
问题描述
我正在尝试在我的 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
解决方案
无需设置框架UIRefreshControl
我通常使用以下步骤来实现它:
在类属性块中:
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
}
希望能帮助到你。
PS 有时会出现刷新控制闪烁错误(与您的有些相似)。可以通过将:添加extendedLayoutIncludesOpaqueBars = true
到您的viewDidLoad()
方法来解决。
推荐阅读
- hibernate - Spring Data @Query with Pageable and Sort 不排序
- r - R中的错误消息:替换有(x)行,数据有(y)
- python - 使用 Python 请求时出现“连接中止”错误
- ios - 如何在 Swift/iOS 中使用双线性过滤缩小图像?
- testing - 此会话不支持 appium css 选择器
- c# - 在使用 Powershell Api 时,有什么方法可以在 C# 中将 PSObject 转换为字符串
- excel - 引用 PowerPoint 幻灯片时 Excel 崩溃
- regex - 正则表达式替换数字后的最后一个“K”
- c# - 程序在 Async/Await 中的 await 完成之前执行
- node.js - 如何将数据附加到 mongodb 和 node.js 中的字段