0

I want to implement the following sort of view where the view can be completely scrolled and houses 2 different scrollview (Main and the secondary) with infinite scrollable content. This represents the exact thing I want.

enter image description here

  1. The red view is superview - should scroll vertically
  2. The green view is of the height of the current view and is just static. That doesnt scroll
  3. The blue view is the horizontal scrollview where for each label there is a yellow vertically scrolling infinity collection view
  4. the labels scroll as in the given video. under each label there is the collection view I mentioned in point 3

The blue box is the scroll view and I want the scrolling to happen horizontally in a parallax way such as this.

enter image description here

I am able to implement the above parallax in the correct fashion but each title contains their own collectionview. When I implement this I am not able to have an infinite scroll. Below is the code for that :

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView == containerScrollView {
        for i in 0..<shotsData.count {
            let label = scrollView.viewWithTag(i + tagValueL) as! UILabel
            let view = scrollView.viewWithTag(i + tagValueV) as! ShotsMediaView
            let scrollContentOffset = scrollView.contentOffset.x + scrollView.frame.width
            let viewOffset = (view.center.x - scrollView.bounds.width/4) - scrollContentOffset
            label.center.x = scrollContentOffset - ((scrollView.bounds.width/4 - viewOffset)/2)
        }
    }
}

How can I exactly achieve the same behavior with an infinite scroll vertically? I want each of these titles to have collectionview that have the dynamic height each.

13
  • Do you want both the upper and lower views to scroll left-right so they both have the same behavior? What is the relationship between the upper and lower views, if any? Commented May 28, 2019 at 21:05
  • I updated the question. The upper view is just an image. the lower view is like a group of cell that just as in representation of the twitter screenshot. The topview is just static but the lower views have feed like content. And there are 2 tabs Commented May 28, 2019 at 21:11
  • The issue is I have been able to implement a view where the top view is a CollectionViewHeader(ReusableView). and then the scrollview in the gif is in a cell. But I am not able to give it an infinite height. Now I am looking to implement a different architecture as in the diagram Commented May 28, 2019 at 21:13
  • @jay Anything on it yet? Commented May 28, 2019 at 22:04
  • 1
    was actually waiting for your answer. Thanks man. Once I find a way. I'll share it with you. Commented Jun 3, 2019 at 5:09

1 Answer 1

2

I did a crude implementation of this.

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView == colorsCollectionView {
        let newContentOffSetX = scrollView.contentOffset.x
        let distance = contentOffSetX + newContentOffSetX
        // Scroll the text collection view proportinately
        let titleScrollDistance = (distance/colorsCollectionView.frame.width * 75.0)
        titlesCollectionView.contentOffset = CGPoint(x: titleScrollDistance, y: titlesCollectionView.contentOffset.y)
        contentOffSetX = newContentOffSetX
    }
}

contentOffSetX is a property of the class(ViewController) that I use to keep track of the scrolling distance of the bottom collection view. Initially that is set to 0. When the user scrolls the collection view at the bottom, the above delegate method is called. Then I use the contentOffSet to get the distance that was scrolled along the X-axis. I map that to the width of the title labels(hardcoded as 75.0) to calculate the distance that collection has to be scrolled. Hope this can be refined to serve your purpose, but I am sure that there are better methods out there :)

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I have updated the question with my code, of how I got the gif to work
Thank a ton for this answer @humblePilgrim, I have literally been waiting for a reply. I have a question though, I want these colored to be UIViews scrolling vertically(Collection view) and the size of each is dynamic. I am not sure how can I achieve this? Can you please help me out here. I was able to achieve this result previously. My issue majorly is deciding the height of each scroll. Am I being clear about my question
The vertical scrolling is implemented in the above using a table view. The dynamic height of each row can be achieved using autolayout. See this link raywenderlich.com/8549-self-sizing-table-view-cells

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.