xcode 首选大标题和 RefreshControl 效果不佳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50708081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prefer Large Titles and RefreshControl not working well
提问by Damia Fuentes
I am using this tutorialto implement a pull-to-refresh behavior with the RefreshControl
. I am using a Navigation Bar
. When using normal titles everything works good. But, when using "Prefer big titles" it doesn't work correctly as you can see in the following videos. Anyone knows why? The only change between videos is the storyboard check on "Prefer Large Titles".
我正在使用本教程通过RefreshControl
. 我正在使用一个Navigation Bar
. 使用普通标题时,一切正常。但是,当使用“首选大标题”时,它无法正常工作,正如您在以下视频中看到的那样。有谁知道为什么?视频之间的唯一变化是对“首选大标题”的故事板检查。
采纳答案by Damia Fuentes
At the end what worked for me was:
最后对我有用的是:
In order to fix the RefreshControl progress bar disappearing bug with large titles:
self.extendedLayoutIncludesOpaqueBars = true
In order to fix the list offset after
refreshcontrol.endRefreshing()
:let top = self.tableView.adjustedContentInset.top let y = self.refreshControl!.frame.maxY + top self.tableView.setContentOffset(CGPoint(x: 0, y: -y), animated:true)
为了修复带有大标题的 RefreshControl 进度条消失的错误:
self.extendedLayoutIncludesOpaqueBars = true
为了在之后修复列表偏移量
refreshcontrol.endRefreshing()
:let top = self.tableView.adjustedContentInset.top let y = self.refreshControl!.frame.maxY + top self.tableView.setContentOffset(CGPoint(x: 0, y: -y), animated:true)
回答by Bruno Cunha
I'm having the same problem, and none of the other answers worked for me.
我遇到了同样的问题,其他答案都不适合我。
I realised that changing the table view top constraint from the safe areato the superviewfixed that strange spinning bug.
我意识到,改变从表视图顶部约束安全区的上海华定那个陌生的纺纱错误。
Also, make sure the constant value for this constraint is 0 .
此外,请确保此约束的常量值为 0 。
回答by atish vishwakarma
If you were using tableView.tableHeaderView = refreshControl
or tableView.addSubView(refreshControl)
you should try using tableView.refreshControl = refreshControl
如果你正在使用tableView.tableHeaderView = refreshControl
或者tableView.addSubView(refreshControl)
你应该尝试使用tableView.refreshControl = refreshControl
回答by Luke Pearce
It seems there are a lot of different causes that could make this happen, for me I had a TableView embedded within a ViewController. I set the top layout guide of the tableview to the superview with 0. After all of that still nothing until I wrapped my RefreshControl end editing in a delayed block:
似乎有很多不同的原因可能会导致这种情况发生,对我来说,我在 ViewController 中嵌入了一个 TableView。我使用 0 将 tableview 的顶部布局指南设置为 superview。毕竟,直到我将我的 RefreshControl 结束编辑包裹在一个延迟块中之前,仍然什么都没有:
DispatchQueue.main.async {
if self.refreshControl.isRefreshing {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
self.refreshControl.endRefreshing()
})
}
}
回答by Victor
The only solution that worked for me using XIBs was Bruno's one: https://stackoverflow.com/a/54629641/2178888
使用 XIB 对我有用的唯一解决方案是布鲁诺的解决方案:https://stackoverflow.com/a/54629641/2178888
However I did not want to use a XIB. I struggled a lot trying to make this work by code using AutoLayout.
但是我不想使用 XIB。我努力尝试使用 AutoLayout 通过代码来完成这项工作。
I finally found a solution that works:
我终于找到了一个有效的解决方案:
override func loadView() {
super.loadView()
let tableView = UITableView()
//configure tableView
self.view = tableView
}
回答by Andreichev Michail
Problem can be solved if add tableview or scroll view as root view in UIViewController hierarchy (like in UITableViewController)
如果在 UIViewController 层次结构中添加 tableview 或滚动视图作为根视图,问题可以解决(如在 UITableViewController 中)
override func loadView() {
view = customView
}
where customView is UITableView or UICollectionView
其中 customView 是 UITableView 或 UICollectionView
回答by Asi Givati
I had this issue too, and i fixed it by embedded my scrollView (or tableView \ collectionView) inside stackView, and it's important that this stackView's top constraint will not be attached to the safeArea view (all the other constraints can). the top constraint should be connect to it's superview or to other view.
我也有这个问题,我通过在 stackView 中嵌入我的 scrollView(或 tableView\collectionView)来修复它,重要的是这个 stackView 的顶部约束不会附加到 safeArea 视图(所有其他约束都可以)。顶部约束应该连接到它的超级视图或其他视图。
回答by Balaji G
I've faced the same problem. Call refreshControl endRefreshing before calling further API.
我遇到了同样的问题。在调用进一步的 API 之前调用 refreshControl endRefreshing。
refreshControl.addTarget(controller, action: #selector(refreshData(_:)), for: .valueChanged)
@objc func refreshData(_ refreshControl: UIRefreshControl) {
refreshControl.endRefreshing()
self.model.loadAPICall {
self.tableView.reloadData()
}
}
回答by Trzy Gracje
The only working solution for me is combining Bruno's suggestionwith this line of code:
对我来说唯一可行的解决方案是将布鲁诺的建议与这行代码结合起来:
tableView.contentInsetAdjustmentBehavior = .always
tableView.contentInsetAdjustmentBehavior = .always