SYParallaxScrollView 0.2.0

SYParallaxScrollView 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年12月
SwiftSwift 版本3.0
SPM支持 SPM

SYParallaxScrollViewTrunk 维护。



SYParallaxScrollView

Version
License
Platform

Demo Animation

您可以在上面的示例项目中看到代码。
demo project code

使用方法

  • 首先,您必须定义 SYParallaxViewItem 对象。
let view = UIView(...)
let item = SYParallaxViewItem(view: view,
                      originOffset: CGPoint(x: 150, y: 80),
                      acceleration: SYParallaxAcceleration.invariable(CGPoint(x: 1, y: 1)),
                          progress: { (parallaxView, view) in
                                       //...
                                    }
                              )

如果您愿意,您还可以定义一个动态加速度。

let dynamicAcceleration = SYParallaxAcceleration.variable { (parallaxView, view) -> CGPoint in
	let progressRatio = (parallaxView.contentSize.width - 3 * parallaxView.contentOffset.x) / parallaxView.contentSize.width
	return CGPoint(x: 0.65 * progressRatio, y: 0.65 * (1 - progressRatio))
}

let view = UIView(...)
let item = SYParallaxViewItem(view: view,
                      originOffset: CGPoint(x: 150, y: 80),
                      acceleration: dynamicAcceleration,
                          progress: { (parallaxView, view) in
                                       //...
                                    }
                              )
  • 其次,构建一个视差视图。
let parallaxView = SYParallaxScrollViewBuilder.setOption { (option) in
                        option.frame = CGRect(x: 0, y: 100, width: view.frame.size.width, height: view.frame.size.height - 100)
                        option.parallaxViewItems = [item] // You can add more items.
                        option.isPagingEnabled = false
                   }.build()
parallaxView.delegate = self //Optional

要求

Minimum iOS Target : iOS 8.0

安装

SYParallaxScrollView 通过 CocoaPods 可用。要安装它,只需将以下行添加到您的 Podfile 中即可

pod 'SYParallaxScrollView'

作者

[email protected]

许可证

SYParallaxScrollView 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。