Implement twitter Profile like view with parallax scroll

前端 未结 1 551
梦谈多话
梦谈多话 2021-01-26 05:37

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 cont

相关标签:
1条回答
  • 2021-01-26 06:14

    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 :)

    0 讨论(0)
提交回复
热议问题