ios - 在我的 tableView 中滚动时如何隐藏 collectionView (知道这个 ViewCOntroller 是一半 tableview 和一半 collectionview )

标签 ios swift uitableview uicollectionview

所以我有一个UIViewController,它有一个带有水平滚动的collectionView(就像newsFeed页面顶部的facebook故事),它下面是tableView 与细胞。当我向下滚动 tableView 时,如何隐藏此 Collection View ?我希望它像 Facebook 一样。

so I have the stories on top as collectionViews

最佳答案

您必须设置collectionView高度约束,并且当您开始拖动表格 View 时:

heightConstraint.constant = 0

您可以从 TableView 委托(delegate)中了解开始拖动。为此,您应该从 UITableViewDelegate 继承 viewController 并设置一个函数:

class ViewController: UIViewController, UITableViewDelegate {
    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.delegate = self
    }

    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
    print("begin dragging")
    heightConstraint.constant = 0
    }
}

关于ios - 在我的 tableView 中滚动时如何隐藏 collectionView (知道这个 ViewCOntroller 是一半 tableview 和一半 collectionview ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603731/

相关文章:

ios - UITextView 在 iPhone 6+ 中自动改变颜色,这不是必需的

ios - 通知中心无法通过 Swift iOS 中的 AppDelegate 运行

ios - 快速对齐标签

ios - XCode 7.1.1 TableViewCell 的内容 View 比单元格窄

ios - iOS Mobile Safari滚动:减速时的DOM操作?

ios - 如何使用按钮处理 UITableViewCell 中的多点触控?

iOS位置转换

android - PhoneGap 开发者应用下载错误

ios - 异常 'NSInternalInconsistencyException' ,原因 : 'Could not load NIB in bundle: . ..有人可以找出这有什么问题吗

ios - 选择时如何更改位于 tableVIewCell 上的 UIButton 的图像。在 swift 3