如何在Swift中向上滚动整个表格视图? [英] How to scroll up an entire table view in Swift?

查看:108
本文介绍了如何在Swift中向上滚动整个表格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在顶部有一个水平滚动的分页collectionview,在底部有一个tableview,就像这样:

I have a horizontal scrolling paged collectionview on top, and a tableview at the bottom, like this:

我想要实现的是,当用户向上滚动表格视图时,我希望整个页面向上滚动.当前,向上滚动时,表视图被限制在底部空间.许多应用程序都具有这种模式,但是Fiverr应用程序是一个示例,下面是屏幕截图.第二张图片是当我开始向上滚动时:

What I'm trying to achieve is that when the user scrolls up the table view, I want the whole page to scroll upwards. Currently, the tableview is confined to the bottom space when scrolling up. Lots of apps have this pattern, but the Fiverr app is an example, and here is a screenshot. The second picture is when I started to scroll up:

我是Swift的入门者,所以我什至不知道要搜索什么关键字.最简单的方法是什么?

I am a complete beginner in Swift so I have no idea even what keywords to search for. What would be the easiest way to accomplish this?

推荐答案

我认为您想将所有视图放入UIScrollView.

I think you want to put all the views into a UIScrollView.

您还可以将UICollectionView放入表的标题视图中.但是,如果您在UITableView下还有更多组件,我发现将整个内容放入UIScrollView会更容易.

You can also put the UICollectionView into the table's header view. But if you have more components below the UITableView, I find it easier to just put the whole thing into a UIScrollView.

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = UIView()
    //build header view here
    headerView.addSubview(collectionView)
    return headerView
}

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    //Return the height of the headerview.
    return height
}

编辑以回答评论:)

这篇关于如何在Swift中向上滚动整个表格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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