{"id":2322,"url":"https://github.com/marmelroy/Interpolate","last_synced_at":"2025-08-06T12:31:47.076Z","repository":{"id":52239891,"uuid":"54623002","full_name":"marmelroy/Interpolate","owner":"marmelroy","description":"Swift interpolation for gesture-driven animations","archived":false,"fork":false,"pushed_at":"2021-01-17T15:20:18.000Z","size":1057,"stargazers_count":1830,"open_issues_count":1,"forks_count":70,"subscribers_count":37,"default_branch":"master","last_synced_at":"2024-11-30T06:06:20.459Z","etag":null,"topics":["animation","gesture-driven-animations","gesture-recognizer","interactive","interpolation","ios","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marmelroy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T07:28:03.000Z","updated_at":"2024-11-26T20:26:43.000Z","dependencies_parsed_at":"2022-08-20T20:50:37.532Z","dependency_job_id":null,"html_url":"https://github.com/marmelroy/Interpolate","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FInterpolate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FInterpolate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FInterpolate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FInterpolate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marmelroy","download_url":"https://codeload.github.com/marmelroy/Interpolate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228570396,"owners_count":17938646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","gesture-driven-animations","gesture-recognizer","interactive","interpolation","ios","swift"],"created_at":"2024-01-05T20:16:10.849Z","updated_at":"2024-12-09T13:30:33.345Z","avatar_url":"https://github.com/marmelroy.png","language":"Swift","funding_links":[],"categories":["UI","Libs","Minor","Animation","UI and SwiftUI","Swift","Animation [🔝](#readme)"],"sub_categories":["Animation","Other free courses"],"readme":"![Interpolate - Swift interpolation for gesture-driven animations](https://cloud.githubusercontent.com/assets/889949/14937965/8b70c90a-0f16-11e6-972a-0ffa39df3e3d.png)\n\n\n[![Platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20tvOS-orange.svg)](https://github.com/marmelroy/Interpolate)\n[![Build Status](https://travis-ci.org/marmelroy/Interpolate.svg?branch=master)](https://travis-ci.org/marmelroy/Interpolate)\n[![Version](http://img.shields.io/cocoapods/v/Interpolate.svg)](http://cocoapods.org/?q=Interpolate)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n# Interpolate\nInterpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"http://i.giphy.com/26FxolLz3AR1oz61y.gif\" width=\"242\" height=\"425\"/\u003e\u003c/p\u003e\n\n## Usage\n\nThe :key: idea  of Interpolate is -\n**all animation is the interpolation of values over time.**    \n\nTo use Interpolate:\n\nImport Interpolate at the top of your Swift file.\n\n```swift\nimport Interpolate\n```\n\nCreate an Interpolate object with a from value, a to value and an apply closure that applies the interpolation's result to the target object.\n\n```swift\nlet colorChange = Interpolate(from: UIColor.white,\nto: UIColor.red,\napply: { [weak self] (color) in\n    self?.view.backgroundColor = color\n})\n```\n\nAlternatively, you can specify multiple values for the interpolation in an array. The Swift compiler might have issues to infer the type of the array so it's best to be explicit.\n```swift\nlet colors: [UIColor] = [UIColor.white, UIColor.red, UIColor.green]\nlet colorChange = Interpolate(values: colors,\napply: { [weak self] (color) in\n    self?.view.backgroundColor = color\n})\n```\n\nNext, you will need to define a way to translate your chosen gesture's progress to a percentage value (i.e. a CGFloat between 0.0 and 1.0).\n\nFor a gesture recognizer or delegate that reports every step of its progress (e.g. UIPanGestureRecognizer or a ScrollViewDidScroll) you can just apply the percentage directly to the Interpolate object:\n```swift\n@IBAction func handlePan(recognizer: UIPanGestureRecognizer) {\n    let translation = recognizer.translation(in: self.view)\n    let translatedCenterY = view.center.y + translation.y\n    let progress = translatedCenterY / self.view.bounds.size.height\n    colorChange.progress = progress\n}\n```\n\nFor other types of gesture recognizers that only report a beginning and an end (e.g. a UILongPressGestureRecognizer), you can animate directly to a target progress value with a given duration. For example:\n```swift\n@IBAction func handleLongPress(recognizer: UILongPressGestureRecognizer) {\n    switch recognizer.state {\n        case .began:\n            colorChange.animate(1.0, duration: 0.3)\n        case .cancelled, .ended, .failed:\n            colorChange.animate(0.0, duration: 0.3)\n        default: break\n    }\n}\n```\n\nTo stop an animation:\n```swift\ncolorChange.stopAnimation()\n```\n\nWhen you are done with the interpolation altogether:\n```swift\ncolorChange.invalidate()\n```\n\nVoila!\n\n## What can I interpolate?\n\nInterpolate currently supports the interpolation of:\n- CGPoint\n- CGRect\n- CGSize\n- Double\n- CGFloat\n- Int\n- NSNumber\n- UIColor\n- CGAffineTransform\n- CATransform3D\n- UIEdgeInsets\n\nMore types will be added over time.\n\n## Advanced usage\n\nInterpolate is not just for dull linear interpolations.\n\nFor smoother animations, consider using any of the following functions: **easeIn, easeOut, easeInOut and Spring.**\n\n```swift\n// Spring interpolation\nlet shadowPosition = Interpolate(from: -shadowView.frame.size.width,\nto: (self.view.bounds.size.width - shadowView.frame.size.width)/2,\nfunction: SpringInterpolation(damping: 30.0, velocity: 0.0, mass: 1.0, stiffness: 100.0),\napply: { [weak self] (originX) in\n    self?.shadowView.frame.origin.x = originX\n})\n\n// Ease out interpolation\nlet groundPosition = Interpolate(from: CGPoint(x: 0, y: self.view.bounds.size.height),\nto: CGPoint(x: 0, y: self.view.bounds.size.height - 150),\nfunction: BasicInterpolation.easeOut,\napply: { [weak self] (origin) in\n    self?.groundView.frame.origin = origin\n})\n```\n\nIn fact, you can easily create and use your own interpolation function - all you need is an object that conforms to the InterpolationFunction protocol.\n\n### Setting up with [CocoaPods](http://cocoapods.org/?q=Interpolate)\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\npod 'Interpolate', '~\u003e 1.3.0'\n```\n\n### Setting up with Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate Interpolate into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"marmelroy/Interpolate\"\n```\n\n### Inspiration\n- [https://github.com/icanzilb/EasyAnimation](https://github.com/icanzilb/EasyAnimation)\n- [https://github.com/robb/RBBAnimation](https://github.com/robb/RBBAnimation)\n- [https://github.com/facebook/pop](https://github.com/facebook/pop)\n- [http://bojackhorseman.com](http://bojackhorseman.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelroy%2FInterpolate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarmelroy%2FInterpolate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelroy%2FInterpolate/lists"}