react 前端框架如何驱动企业数字化转型与创新发展
714
2022-10-24
Popsicle - 简单的、可扩展的插值框架
THIS PROJECT IS NO LONGER MAINTAINED.
Popsicle is a Swift framework for creating and managing interpolations of different value types with built-in UIKit support.
Installation
Carthage
github "DavdRoman/Popsicle"
CocoaPods
pod 'Popsicle'
Manual
Drag and copy all files in the Popsicle folder into your project.
At a glance
Interpolating UIView (or any other NSObject) values
First, you need an Interpolator instance:
let interpolator = Interpolator()
Next, you need to add some Interpolation
let interpolation = Interpolation(yourView, alpha)interpolation[0] = 0interpolation[150] = 1self.interpolator.addInterpolation(interpolation)
Note alpha is a built-in KeyPath
You can also modify the easing function used at a given time:
interpolation.setEasingFunction(EasingFunctionEaseOutQuad, forTime: 0)
There's a bunch of built-in easing functions to choose from.
Finally, just make your interpolator vary its time depending on whatever you want. For example, the content offset of a UITableView:
func scrollViewDidScroll(scrollView: UIScrollView) { interpolator.time = Double(scrollView.contentOffset.y)}
Interpolating custom values
You can declare a value type as interpolable by making it conform to the Interpolable protocol.
As an example, check out how CGPoint conforms to Interpolable:
extension CGSize: Interpolable { public static func interpolate(from fromValue: CGSize, to toValue: CGSize, withProgress progress: Progress) -> CGSize { let width = CGFloat.interpolate(from: fromValue.width, to: toValue.width, withProgress: progress) let height = CGFloat.interpolate(from: fromValue.height, to: toValue.height, withProgress: progress) return CGSizeMake(width, height) } public static func objectify(value: CGSize) -> AnyObject { return NSValue(CGSize: value) }}
License
Popsicle is available under the MIT license.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~