0

如果用户到达表格视图的底部但继续向上滚动,我正在尝试向用户显示“仅此而已”消息,就像聊天底部显示的“你是最新的”消息松弛一样。但是,tableFooterView可以在表格视图的最底部看到并且没有隐藏。这应该怎么做?

4

3 回答 3

1

我使用这个解决方案:

let test=UILabel(frame: CGRect(x: 0,y: tableView.contentSize.height+180, width: tableView.frame.width, height: 50))
test.text="That's all"
view.insertSubview(test, belowSubview: tableView)
于 2017-03-06T17:42:40.357 回答
0

添加页脚视图将不起作用,因为随后 tableview 将调整其 contentSize 以显示它。

你可以直接给 UITableView 添加一个子视图,设置它的 frame 的 origin.y 大于 contextSize.y。每当您添加或删除行,或添加或删除部分部分或重新加载表格时,您都必须重新调整视图。

于 2017-03-06T15:12:12.693 回答
0

我遇到了同样的问题,上述解决方案对我不起作用。

我最终使用了自动布局约束。最初,页脚视图的底部锚点设置为更大的常量以使其不可见

然后使用滚动视图委托的开始和结束拖动方法来显示和隐藏它

extension ViewController: UITableViewDelegate {
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        guard let bottomAnchor = self.bottomAnchor else { return }
        guard scrollView.contentSize.height > scrollView.frame.size.height else { return }
        let heightOfInvisibleContent = (scrollView.contentSize.height - scrollView.frame.size.height)
        print("height of invisible content: \(heightOfInvisibleContent), offset: \(scrollView.contentOffset.y)")
        guard scrollView.contentOffset.y >= heightOfInvisibleContent else { return }
        bottomAnchor.constant = moveUpConstant
        UIView.animate(withDuration: 0.5) {
            self.view.layoutIfNeeded()
        }
    }

    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        guard let bottomAnchor = self.bottomAnchor else { return }
        bottomAnchor.constant = moveDownConstant
        UIView.animate(withDuration: 0.5) {
            self.view.layoutIfNeeded()
        }
    }
}

我在我的仓库https://github.com/ramjyroo/iOS-Expedition中分享了我的完整示例项目(FooterMessage)

于 2018-01-06T03:49:20.953 回答