Beautiful parallax effect for your Table/Collection cells. (Or something else)
Add
pod 'Parallaxable'
to your podfile, and run
pod install
Out of the box, Parallaxable calculates parallax offset for any collection/table cell.
For enable calculation you need to set:
tableView.isParallaxEnabled = true
Also you need to conform protocol Parallaxable
with your cell like:
let parallaxOffsetMultiplier: CGFloat = 20
extension TableCell: Parallaxable {
func updateVerticalParallaxOffset(with offset: CGFloat) {
var targetCenter = contentView.center
targetCenter.x = imageView.center.x
targetCenter.y += offset * parallaxOffsetMultiplier
imageView.center = targetCenter
}
func updateHorizontalParallaxOffset(with offset: CGFloat) {
var targetCenter = contentView.center
targetCenter.x += offset * parallaxOffsetMultiplier
targetCenter.y = imageView.center.y
imageView.center = targetCenter
}
}
Code above will offset TableCell
's imageView from center by offset
.
offset
is value from -1
to 1
representing position of cell relative to table/collection view's center.