Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DavdRoman/Popsicle
Simple, extensible interpolation framework
https://github.com/DavdRoman/Popsicle
Last synced: 7 days ago
JSON representation
Simple, extensible interpolation framework
- Host: GitHub
- URL: https://github.com/DavdRoman/Popsicle
- Owner: davdroman
- License: mit
- Archived: true
- Created: 2013-09-17T17:09:34.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T20:11:22.000Z (about 2 years ago)
- Last Synced: 2024-12-04T21:25:37.926Z (8 days ago)
- Language: Swift
- Homepage:
- Size: 1.76 MB
- Stars: 1,088
- Watchers: 36
- Forks: 105
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Popsicle - Delightful, extensible Swift value interpolation framework. (UI / Animation)
- awesome-ios-star - Popsicle - Delightful, extensible Swift value interpolation framework. (UI / Animation)
- awesome-swift-cn - Popsicle - Delightful, extensible Swift value interpolation framework. (Libs / Utility)
README
> **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
```ruby
pod 'Popsicle'
```#### Manual
Drag and copy all files in the [__Popsicle__](Popsicle) folder into your project.
## At a glance
#### Interpolating UIView (or any other NSObject) values
First, you need an `Interpolator` instance:
```swift
let interpolator = Interpolator()
```Next, you need to add some `Interpolation` instances to your interpolator. In the example below, we are going to interpolate the alpha value of a UIView for times between 0 and 150:
```swift
let interpolation = Interpolation(yourView, alpha)
interpolation[0] = 0
interpolation[150] = 1
self.interpolator.addInterpolation(interpolation)
```Note `alpha` is a built-in `KeyPath` constant. Popsicle offers a nice set of [__UIKit-related KeyPaths__](Popsicle/KeyPath.swift) ready to be used. You may also use a completely custom key path.
You can also modify the easing function used at a given time:
```swift
interpolation.setEasingFunction(EasingFunctionEaseOutQuad, forTime: 0)
```There's a bunch of [__built-in easing functions__](Popsicle/EasingFunction.swift) to choose from.
Finally, just make your `interpolator` vary its `time` depending on whatever you want. For example, the content offset of a `UITableView`:
```swift
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`:
```swift
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.