[英]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: 我通常使用以下步骤实现它:
let refreshControl: UIRefreshControl = UIRefreshControl()
viewDidLoad
: 在viewDidLoad
: collectionView.alwaysBounceVertical = true
collectionView.refreshControl = refreshControl
refreshControl.addTarget(self, action: #selector(loadData), for: .valueChanged)
// 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.