How to change the content offset of a UICollectionView simultaneously?


Please briefly explain why you feel this question should be reported .

Report Cancel

I have a horizontal scrollable collectionView with two cells that take up the screen. Inside those cells is an embedded collection view that scrolls vertically. Is there a way for me to scroll the vertical CV inside the first cell, while using its ContentOffset to scroll the vertical CV in the second cell?

Here’s how I’m trying to accomplish it:

let scrollView = notification.userInfo!["scrollView"] as! UICollectionView
if scrollView.contentOffset.y <= 250.0 {
   childViewControllerForPosts.collectionViewForGroups?.collectionView.setContentOffset(CGPointMake(0, scrollView.contentOffset.y), animated: false)

        self.topVerticalConstraint?.constant = -scrollView.contentOffset.y

    else {

        if self.topVerticalConstraint?.constant > -250 {
            // Make sure it stays at -250
            self.topVerticalConstraint?.constant = -250


The FeedCell would be the main collection view (which horizontally scrolls) that contains the vertical scrolling collection view. I’m trying to access the second one to change the vertical contentOffset when I scroll the one in first one.

Here’s how I’m trying to save the variable that should contain the second main collection view:

collectionViewForGroups = collectionView(collectionView!, cellForItemAtIndexPath: NSIndexPath(forItem: 1, inSection: 0)) as? FeedCell

Note that when I scroll horizontally, the vertical scroll view didn’t change. But I want it to change with the one I just scrolled in the gif. If I were to scroll the 2nd vertical collection view, the UIView above will reappear because the topLayConstraint changes due to the vertical contentOffset change.

enter image description here

0 Answer 28 views 0