使用大标题时,iOS 11滚动到顶部无法正常工作 [英] iOS 11 scroll to top when using large titles doesn't work properly
问题描述
使用大标题并点击状态栏以滚动到UIScrollView
或UITableView
(可能也是UICollectionView
,尚未测试)的顶部时,它总是有点过头.
我已在TableView
上启用了刷新功能,当点击状态栏时,它看起来像这样,并一直保持这种状态,直到我点击屏幕为止.
我在另一个ViewController
中有一个ScrollView
,如果我点击状态栏,它还会滚动得太远,使导航栏过高.当我点击某个地方或滚动一点时,这也恢复正常.
正常:
点击状态栏后:
这也只有在我激活了大标题时才发生,使用普通标题,一切都会正常进行.
有什么办法解决这个问题吗?
如何重新创建:
- 使用导航控制器和内部带有
TableView
的UIViewController
创建一个新项目. - 将导航控制器设置为喜欢大标题.关闭半透明.在
UIViewController
上设置标题
- 在
TableView
上设置约束以固定到ViewController
的边缘
- 在
ViewController
中为 - 实施委托并设置行数,例如100
- 启动应用
- 向下滚动,使大标题变成普通标题
- 点击状态栏,以便
tableView
滚动到顶部
TableView
创建出口
现在标题不在应有的位置,如果现在向上或向下滚动一点,标题将恢复到正常位置.
ViewController
代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath)
return cell
}
}
好的,所以我找到了问题发生的原因,但没有找到在确切的情况下解决问题的方法.
如果您使用大标题,并且UITableViewController的导航栏半透明性设置为关闭,则会出现此问题. 当您重新打开半透明按钮时,问题就消失了.
如果您在普通的UIViewController中使用TableView,则总是会出现此问题.
修改
如果您使用的是半透明导航栏,则设置"extendedLayoutIncludesOpaqueBars = true"可以解决该问题!
类似的问题: iOS 11 Glitchy效果中的UIRefreshControl() >
When using large titles and tapping the status bar to scroll to the top of a UIScrollView
or UITableView
(probably also UICollectionView
, haven't tested this) it always goes a little too far.
I have refresh enabled on my TableView
and when tapping the status bar it appears like this and stays that way until I tap the screen.
I have a ScrollView
in another ViewController
and if I tap the status bar there it also scrolls a little bit too far, making the navigation bar too tall. This also returns to normal when I tap somewhere or scroll a tiny bit.
Normal:
After I tapped the status bar:
This also only happens when I have large titles activated, using normal titles everything works as it should.
Any ideas how to fix this?
How to recreate:
- Create a new project with a navigation controller and a
UIViewController
with aTableView
inside. - Set navigation controller to prefer large titles. Turn translucent off. Set title on
UIViewController
- Set constraints on
TableView
to pin to the edges of theViewController
- Create outlet for
TableView
in theViewController
- Implement delegates and set a number of rows, for example 100
- Launch app
- Scroll down so the large title becomes a normal title
- Tap status bar so the
tableView
scrolls to the top
Now the title is not at the position it should be, if you now scroll a tiny bit up or down it snaps back to the normal position.
ViewController
code:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath)
return cell
}
}
Okay so I found why the problem occurs, but not how to fix it in that exact scenario.
If you're using large titles and a UITableViewController with the navigation bar translucency set to off the problem will occur. When you turn translucent back on the problem goes away.
If you're using a TableView in a normal UIViewController the problem always occurs.
Edit
Turns out setting "extendedLayoutIncludesOpaqueBars = true" fixes the problem if you're using a translucent navigation bar!
Similar question: UIRefreshControl() in iOS 11 Glitchy effect
这篇关于使用大标题时,iOS 11滚动到顶部无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!