Kodeco Forums

Video Tutorial: Custom Collection View Layouts Part 13: Timbre – Parallax Effect

Learn how to add the final touches to your Timbre layout by creating a really cool parallax effect.


This is a companion discussion topic for the original entry at https://videos.raywenderlich.com/courses/6-custom-collection-view-layout/lessons/14

I didn’t understand why “maxVerticalOffset” was being calculated and used the way it was, so I came up with my own solution:

func updateImageOffset(collectionViewBounds bounds: CGRect) {
    let frameOffset = CGRectGetMidY(bounds) - CGRectGetMidY(self.frame)
    let offsetScale = (self.bounds.height / bounds.height)
    let maxOffset = CGRectGetMidY(self.backgroundImageView.bounds) - CGRectGetMidY(self.bounds)
    let offset = frameOffset * offsetScale
    self.verticalOffsetConstraint.constant = min(offset, maxOffset)
}

It would have been helpful if you explained the “why” behind some of the math you are doing in each of the layouts in these tutorial videos.