Parallaxable 0.0.3

Parallaxable 0.0.3

Maxim Kotliar 维护。



  • Maxim Kotliar

Version License Platform

Parallaxable

为您的 Table/Collection cells 提供美丽的视差效果。(或其它什么)

安装

添加

pod 'Parallaxable'

到您的 podfile 中,并运行

pod install

使用方法

默认情况下,Parallaxable 为任何 collection/table cell 计算视差偏移。

为了启用计算,您需要设置

tableView.isParallaxEnabled = true

此外,您还需要像以下一样将您的 cell 适配到 Parallaxable 协议

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
    }
}

上述代码将把 TableCell 的 imageView 从中心偏移 offset

offset 是从 -11 的值,表示 cell 相对于 table/collection view 的中心的位置。