UIRefreshControl 出现在集合视图项的顶部而不是后面
UIRefreshControl appears on top of collection view items instead of behind
我有一个 UICollectionView
带有常规拉动刷新实现,但不知何故微调器和 "pull to refresh" 文本出现在集合视图项目上方;
我怎样才能把它放在物品后面?
这就是我将 UIRefreshControll
添加到 UICollectionView
的方式
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull down to refresh")
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: UIControlEvents.valueChanged)
collectionView?.refreshControl = refreshControl
我解决这个问题的方法是将 refreshControll
zPosition
更改为每个视图后面的内容如下:
refreshControl.layer.zPosition = -1
希望这对任何人有进一步的帮助。
试试这个:
@IBOutlet weak var collectionView: UICollectionView!
var refresher:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
let refresher = UIRefreshControl()
self.collectionView!.alwaysBounceVertical = true
self.refresher.tintColor = UIColor.red
self.refresher.addTarget(self, action: #selector(loadData), for: .valueChanged)
self.collectionView!.addSubview(refresher)
}
func loadData() {
//code to execute during refresher
.
.
.
stopRefresher() //Call this to stop refresher
}
func stopRefresher() {
self.refresher.endRefreshing()
}
我有一个 UICollectionView
带有常规拉动刷新实现,但不知何故微调器和 "pull to refresh" 文本出现在集合视图项目上方;
我怎样才能把它放在物品后面?
这就是我将 UIRefreshControll
添加到 UICollectionView
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull down to refresh")
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: UIControlEvents.valueChanged)
collectionView?.refreshControl = refreshControl
我解决这个问题的方法是将 refreshControll
zPosition
更改为每个视图后面的内容如下:
refreshControl.layer.zPosition = -1
希望这对任何人有进一步的帮助。
试试这个:
@IBOutlet weak var collectionView: UICollectionView!
var refresher:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
let refresher = UIRefreshControl()
self.collectionView!.alwaysBounceVertical = true
self.refresher.tintColor = UIColor.red
self.refresher.addTarget(self, action: #selector(loadData), for: .valueChanged)
self.collectionView!.addSubview(refresher)
}
func loadData() {
//code to execute during refresher
.
.
.
stopRefresher() //Call this to stop refresher
}
func stopRefresher() {
self.refresher.endRefreshing()
}