tableView 滚动到顶部时出现大故障

问题描述

请帮助我并就我的问题提供建议。大家好! 我有 navigationBar(顶部白色区域)+ 自定义 HeaderView(橙色区域)+ TableView(绿色/黄色区域) 在向上滚动表格时,我的 customHeaderView 也应该滚动,在这里我将 topContaintAnchor 设置为该 customHeaderView 并在移动 tableView 的 offset.y 值时移动它。当当前 contentOffset 达到 customHeaderLabel 的大小并开始出现故障时,我无法滚动更多的问题。有时它工作得很好,但有时却没有。我在这里做错了什么?我该如何解决

Here is a picture of my problem:

这是我的问题的简短视频:https://drive.google.com/file/d/16fSaWoMj2hdylSIxcrLeK3dEOS8UPf9t/view?usp=sharing

这是一个如何正确工作的视频: https://drive.google.com/file/d/1LmpLW08b7dy0OuTEEaCHHs8koKn1BYMM/view?usp=sharing

这是我的代码

// For HeaderLabel
titleLabelTopConstraint = headerLabel.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
headerLabel.leadingAnchor.constraint(equalTo: leadingAnchor,constant: 15),headerLabel.trailingAnchor.constraint(equalTo: trailingAnchor,constant: -15),headerLabel.bottomAnchor.constraint(equalTo: tableView.topAnchor)

// For TableView
tableView.topAnchor.constraint(equalTo: headerLabel.bottomAnchor),tableView.leadingAnchor.constraint(equalTo: leadingAnchor),tableView.trailingAnchor.constraint(equalTo: trailingAnchor),tableView.bottomAnchor.constraint(equalTo: bottomAnchor),// Delegate
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        guard UIScreen.type != .extraSmall else { return }

        let titleHeight = headerLabel.bounds.height

        if scrollView.contentOffset.y <= 0 {
            // Title is fully visible
            titleLabelTopConstraint.constant = 0
        } else if scrollView.contentOffset.y >= titleHeight {
            // Title is not visible at all
            titleLabelTopConstraint.constant = -titleHeight
        } else {
            // Title is not fully hidden or shown
            titleLabelTopConstraint.constant = -scrollView.contentOffset.y
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...