使用大标题时,iOS 11滚动到顶部无法正常工作 [英] iOS 11 scroll to top when using large titles doesn't work properly

查看:98
本文介绍了使用大标题时,iOS 11滚动到顶部无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用大标题并点击状态栏以滚动到UIScrollViewUITableView(可能也是UICollectionView,尚未测试)的顶部时,它总是有点过头.

我已在TableView上启用了刷新功能,当点击状态栏时,它看起来像这样,并一直保持这种状态,直到我点击屏幕为止.

我在另一个ViewController中有一个ScrollView,如果我点击状态栏,它还会滚动得太远,使导航栏过高.当我点击某个地方或滚动一点时,这也恢复正常.

正常:

点击状态栏后:

这也只有在我激活了大标题时才发生,使用普通标题,一切都会正常进行.

有什么办法解决这个问题吗?

如何重新创建:

  1. 使用导航控制器和内部带有TableViewUIViewController创建一个新项目.
  2. 将导航控制器设置为喜欢大标题.关闭半透明.在UIViewController
  3. 上设置标题
  4. TableView上设置约束以固定到ViewController
  5. 的边缘
  6. ViewController
  7. 中为TableView创建出口
  8. 实施委托并设置行数,例如100
  9. 启动应用
  10. 向下滚动,使大标题变成普通标题
  11. 点击状态栏,以便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:

  1. Create a new project with a navigation controller and a UIViewController with a TableView inside.
  2. Set navigation controller to prefer large titles. Turn translucent off. Set title on UIViewController
  3. Set constraints on TableView to pin to the edges of the ViewController
  4. Create outlet for TableView in the ViewController
  5. Implement delegates and set a number of rows, for example 100
  6. Launch app
  7. Scroll down so the large title becomes a normal title
  8. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆