简体   繁体   中英

How can I hide a collectionView when scrolling in my tableView (knowing that this ViewCOntroller is half tableview and half collectionview)

So I have a UIViewController that have a collectionView with horizontal scrolling (like the facebook stories on the top of newsFeed page) and under it is the tableView with cells. How can I hide this collection view when I scroll down the tableView ? I want it to exactly like facebook.

所以我把故事放在最上面,作为collectionViews

You have to set collectionView height constraint, and when you begin dragging table view:

heightConstraint.constant = 0

You can know about start dragging from table view delegate. For this you should inherit your viewController from UITableViewDelegate and set a function :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM