ios - 如何创建一个顶部是 Collection View 而底部是列表的可 ScrollView ?

标签 ios layout

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

enter image description here

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

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

编辑:

单个 TableView 是否可以将标题作为最近的搜索 Collection View ,其余部分作为表格 View 单元格?

最佳答案

当您滚动整个 View 时,“最近的搜索”是否会向上滚动? (我在我的应用商店中找不到这个应用'

如果是这样,您可以将表格单元格自定义为两种不同的类型,并在第一部分中使用“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 中同时使用“ Collection View ”和“表格 View ”。

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
}

你甚至可以自定义scrollview。(真的不推荐)

关于ios - 如何创建一个顶部是 Collection View 而底部是列表的可 ScrollView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45047875/

相关文章:

ios - iOS 中的数据模型持久性注意事项

ios - 如何向 Collection View 单元格添加按钮

ios - 如何为 iPhone 5 切换到不同的 Storyboard?

android - GridLayout 内的 Spinner

html - 温泉用户界面 : ons-col width

android 寻呼机滑动标签条 fragment 更换器

iphone - 我可以在后台状态下查看iPhone的电池状态吗?

ios - UISegmentedControl 没有执行目标方法?

android - 如何使用自定义行和标题布局预览 Android ListView

android - 扩展 LinearLayout 不旋转