我正在尝试对我的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
答案 0 :(得分:0)
无需为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
}
希望有帮助。
P.S。有时会有刷新控制闪烁错误(某种程度上类似于您的错误)。可以通过在您的extendedLayoutIncludesOpaqueBars = true
方法中添加viewDidLoad()
来解决。