【问题标题】:How to create a scrollable view with a collection view on the top and the list on the bottom?如何创建一个可滚动的视图,顶部是集合视图,底部是列表?
【发布时间】:2017-07-12 11:55:24
【问题描述】:

这是来自应用商店中 Ganna 应用的图片:

当用户点击顶部的搜索栏时会弹出此视图。我相信他们使用UISearchController 实现了它(将ScrollView 传递给UISearchController 的构造函数)并且ScrollView 还包含用于最近搜索的水平滚动CollectionView(在顶部),但我我很困惑他们如何将趋势列表放在下面。这是趋势部分的TableView 吗?

有没有人知道如何构建这种类型的 UI?

编辑:

单个 TableView 是否可以将标题作为最近搜索集合视图而其余部分作为表格视图单元格工作?

【问题讨论】:

    标签: ios layout


    【解决方案1】:

    滚动整个视图时是否会向上滚动“最近搜索”? (我在我的应用商店中找不到这个应用程序'

    如果是这样,您可以将表格单元格自定义为两种不同的类型,并在第一部分中使用“collectionview”。

        override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell : UITableViewCell!
        if indexPath.section == 0 {
            cell = tableView.dequeueReusableCell(withIdentifier: "id of cell contain colletoinview for recent search", for: indexPath)
        } else {
            cell = tableView.dequeueReusableCell(withIdentifier: "id of cell for trending", for: indexPath)
        }
        return cell!
    }
    

    如果没有,您可以在 uiviewcontroller 中同时使用“集合视图”和“表格视图”。

    class SampleController : UIViewController {
        @IBOutlet var trendingTableView : UITableView!
        @IBOutlet var recentSearchCollectionView : UICollectionView!
    }
    
    extension SampleController : UITableViewDelegate, UITableViewDataSource {
        // handle your tableview, Implement protocol
    }
    
    extension SampleController : UICollectionViewDelegate, UICollectionViewDataSource {
        // handle your collectionview, Implement protocol
    }
    

    你甚至可以自定义滚动视图。(真的不推荐)

    【讨论】:

    • 实际上我的想法与您的第一个选项完全相同。您还可以将“最近搜索”CollectionView 设置为标题单元格,而其余的底部部分通常是出列单元格。感谢您的帮助!
    • 非常乐意帮助您。 :)
    • 在 SnapChat 中,我想知道当您单击 Snapchat 中的搜索栏时,您将如何创建显示的视图?我想拥有一个大的TableView。然后在主要的TableView 中创建一个名为Top Stories 的部分并在其中放置一个CollectionView。然后对于下一部分有另一个部分,其中包含所有类别,如(Around MeTravel 等)。然后在该部分中有一个水平的CollectionView,其中包含与类别一样多的单元格,并且在每个单元格中都有一个垂直的CollectionView。你会这样做吗?
    • 只是在寻找一些输入哈哈?
    • 看了半天,也是用谷歌翻译的,但还是没看懂,请给点图~
    猜你喜欢
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    相关资源
    最近更新 更多