This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
77 changed files
with
1,207 additions
and
1,905 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# OS X | ||
|
||
.DS_Store | ||
|
||
# Xcode | ||
|
||
build/ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "Popsicle" | ||
s.version = "1.1.2" | ||
s.summary = "Simple, extensible value interpolation framework" | ||
s.version = "2.0.0" | ||
s.summary = "Delightful, extensible Swift value interpolation framework" | ||
s.homepage = "https://github.com/DavdRoman/Popsicle" | ||
s.author = { "David Roman" => "[email protected]" } | ||
s.author = { "David Román" => "[email protected]" } | ||
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.social_media_url = 'https://twitter.com/DavdRoman' | ||
|
||
s.platform = :ios, '7.1' | ||
s.ios.deployment_target = '7.1' | ||
s.platform = :ios, '8.0' | ||
s.ios.deployment_target = '8.0' | ||
|
||
s.source = { :git => "https://github.com/DavdRoman/Popsicle.git", :tag => s.version.to_s } | ||
s.source_files = 'Popsicle/*.{h,m}' | ||
s.frameworks = 'Foundation', 'UIKit' | ||
s.source_files = 'Popsicle/*.{h,swift}' | ||
s.frameworks = 'UIKit' | ||
s.requires_arc = true | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// EasingFunction.swift | ||
// RazzleDazzle | ||
// | ||
// Created by Laura Skelton on 6/15/15. | ||
// Copyright (c) 2015 IFTTT. All rights reserved. | ||
// | ||
|
||
// Ported to Swift from Robert Böhnke's RBBAnimation, original available here: | ||
// <https://github.com/robb/RBBAnimation/blob/a29cafe2fa91e62573cc9967990b0ad2a6b17a76/RBBAnimation/RBBEasingFunction.m> | ||
|
||
public typealias EasingFunction = (Progress) -> (Progress) | ||
|
||
public let EasingFunctionLinear: EasingFunction = { t in | ||
return t | ||
} | ||
|
||
public let EasingFunctionEaseInQuad: EasingFunction = { t in | ||
return t * t | ||
} | ||
|
||
public let EasingFunctionEaseOutQuad: EasingFunction = { t in | ||
return t * (2 - t) | ||
} | ||
|
||
public let EasingFunctionEaseInOutQuad: EasingFunction = { t in | ||
if (t < 0.5) { return 2 * t * t } | ||
return -1 + ((4 - (2 * t)) * t) | ||
} | ||
|
||
public let EasingFunctionEaseInCubic: EasingFunction = { t in | ||
return t * t * t | ||
} | ||
|
||
public let EasingFunctionEaseOutCubic: EasingFunction = { t in | ||
return pow(t - 1, 3) + 1 | ||
} | ||
|
||
public let EasingFunctionEaseInOutCubic: EasingFunction = { t in | ||
if (t < 0.5) { return 4 * pow(t, 3) } | ||
return ((t - 1) * pow((2 * t) - 2, 2)) + 1 | ||
} | ||
|
||
public let EasingFunctionEaseInBounce: EasingFunction = { t in | ||
return 1 - EasingFunctionEaseOutBounce(1 - t) | ||
} | ||
|
||
public let EasingFunctionEaseOutBounce: EasingFunction = { t in | ||
if (t < (4.0 / 11.0)) { | ||
return pow((11.0 / 4.0), 2) * pow(t, 2) | ||
} | ||
|
||
if (t < (8.0 / 11.0)) { | ||
return (3.0 / 4.0) + (pow((11.0 / 4.0), 2) * pow(t - (6.0 / 11.0), 2)) | ||
} | ||
|
||
if (t < (10.0 / 11.0)) { | ||
return (15.0 / 16.0) + (pow((11.0 / 4.0), 2) * pow(t - (9.0 / 11.0), 2)) | ||
} | ||
|
||
return (63.0 / 64.0) + (pow((11.0 / 4.0), 2) * pow(t - (21.0 / 22.0), 2)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// | ||
// Interpolable.swift | ||
// Popsicle | ||
// | ||
// Created by David Román Aguirre on 01/11/15. | ||
// Copyright © 2015 David Román Aguirre. All rights reserved. | ||
// | ||
|
||
/// A value from 0 to 1 defining the progress of a certain interpolation between two `Interpolable` values. | ||
public typealias Progress = Double | ||
|
||
/// Defines a common protocol for all interpolable values. | ||
/// | ||
/// Types conforming to this protocol are available to use as a `Interpolation` generic type. | ||
public protocol Interpolable { | ||
typealias ValueType | ||
|
||
/// Defines how an interpolation should be performed between two given values of the type conforming to this protocol. | ||
static func interpolate(from fromValue: ValueType, to toValue: ValueType, withProgress: Progress) -> ValueType | ||
|
||
/// Converts a value to a valid `Foundation` object, if necessary. | ||
static func objectify(value: ValueType) -> AnyObject | ||
} | ||
|
||
extension Bool: Interpolable { | ||
public static func interpolate(from fromValue: Bool, to toValue: Bool, withProgress progress: Progress) -> Bool { | ||
return progress >= 0.5 ? toValue : fromValue | ||
} | ||
|
||
public static func objectify(value: Bool) -> AnyObject { | ||
return NSNumber(bool: value) | ||
} | ||
} | ||
|
||
extension CGFloat: Interpolable { | ||
public static func interpolate(from fromValue: CGFloat, to toValue: CGFloat, withProgress progress: Progress) -> CGFloat { | ||
return fromValue+(toValue-fromValue)*CGFloat(progress) | ||
} | ||
|
||
public static func objectify(value: CGFloat) -> AnyObject { | ||
return NSNumber(double: Double(value)) | ||
} | ||
} | ||
|
||
extension CGPoint: Interpolable { | ||
public static func interpolate(from fromValue: CGPoint, to toValue: CGPoint, withProgress progress: Progress) -> CGPoint { | ||
let x = CGFloat.interpolate(from: fromValue.x, to: toValue.x, withProgress: progress) | ||
let y = CGFloat.interpolate(from: fromValue.y, to: toValue.y, withProgress: progress) | ||
|
||
return CGPointMake(x, y) | ||
} | ||
|
||
public static func objectify(value: CGPoint) -> AnyObject { | ||
return NSValue(CGPoint: value) | ||
} | ||
} | ||
|
||
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) | ||
} | ||
} | ||
|
||
extension CGRect: Interpolable { | ||
public static func interpolate(from fromValue: CGRect, to toValue: CGRect, withProgress progress: Progress) -> CGRect { | ||
let origin = CGPoint.interpolate(from: fromValue.origin, to: toValue.origin, withProgress: progress) | ||
let size = CGSize.interpolate(from: fromValue.size, to: toValue.size, withProgress: progress) | ||
|
||
return CGRectMake(origin.x, origin.y, size.width, size.height) | ||
} | ||
|
||
public static func objectify(value: CGRect) -> AnyObject { | ||
return NSValue(CGRect: value) | ||
} | ||
} | ||
|
||
extension CGAffineTransform: Interpolable { | ||
public static func interpolate(from fromValue: CGAffineTransform, to toValue: CGAffineTransform, withProgress progress: Progress) -> CGAffineTransform { | ||
let tx1 = CGAffineTransformGetTranslationX(fromValue) | ||
let tx2 = CGAffineTransformGetTranslationX(toValue) | ||
let tx = CGFloat.interpolate(from: tx1, to: tx2, withProgress: progress) | ||
|
||
let ty1 = CGAffineTransformGetTranslationY(fromValue) | ||
let ty2 = CGAffineTransformGetTranslationY(toValue) | ||
let ty = CGFloat.interpolate(from: ty1, to: ty2, withProgress: progress) | ||
|
||
let sx1 = CGAffineTransformGetScaleX(fromValue) | ||
let sx2 = CGAffineTransformGetScaleX(toValue) | ||
let sx = CGFloat.interpolate(from: sx1, to: sx2, withProgress: progress) | ||
|
||
let sy1 = CGAffineTransformGetScaleY(fromValue) | ||
let sy2 = CGAffineTransformGetScaleY(toValue) | ||
let sy = CGFloat.interpolate(from: sy1, to: sy2, withProgress: progress) | ||
|
||
let deg1 = CGAffineTransformGetRotation(fromValue) | ||
let deg2 = CGAffineTransformGetRotation(toValue) | ||
let deg = CGFloat.interpolate(from: deg1, to: deg2, withProgress: progress) | ||
|
||
return CGAffineTransformMake(tx, ty, sx, sy, deg) | ||
} | ||
|
||
public static func objectify(value: CGAffineTransform) -> AnyObject { | ||
return NSValue(CGAffineTransform: value) | ||
} | ||
} | ||
|
||
/// `CGAffineTransformMake()`, The Right Way™ | ||
/// | ||
/// - parameter tx: translation on x axis. | ||
/// - parameter ty: translation on y axis. | ||
/// - parameter sx: scale factor for width. | ||
/// - parameter sy: scale factor for height. | ||
/// - parameter deg: degrees. | ||
public func CGAffineTransformMake(tx: CGFloat, _ ty: CGFloat, _ sx: CGFloat, _ sy: CGFloat, _ deg: CGFloat) -> CGAffineTransform { | ||
let translationTransform = CGAffineTransformMakeTranslation(tx, ty) | ||
let scaleTransform = CGAffineTransformMakeScale(sx, sy) | ||
let rotationTransform = CGAffineTransformMakeRotation(deg*CGFloat(M_PI_2)/180) | ||
|
||
return CGAffineTransformConcat(CGAffineTransformConcat(translationTransform, scaleTransform), rotationTransform) | ||
} | ||
|
||
func CGAffineTransformGetTranslationX(t: CGAffineTransform) -> CGFloat { return t.tx } | ||
func CGAffineTransformGetTranslationY(t: CGAffineTransform) -> CGFloat { return t.ty } | ||
func CGAffineTransformGetScaleX(t: CGAffineTransform) -> CGFloat { return sqrt(t.a * t.a + t.c * t.c) } | ||
func CGAffineTransformGetScaleY(t: CGAffineTransform) -> CGFloat { return sqrt(t.b * t.b + t.d * t.d) } | ||
func CGAffineTransformGetRotation(t: CGAffineTransform) -> CGFloat { return (atan2(t.b, t.a)*180)/CGFloat(M_PI_2) } | ||
|
||
extension UIColor: Interpolable { | ||
public static func interpolate(from fromValue: UIColor, to toValue: UIColor, withProgress progress: Progress) -> UIColor { | ||
var fromRed: CGFloat = 0 | ||
var fromGreen: CGFloat = 0 | ||
var fromBlue: CGFloat = 0 | ||
var fromAlpha: CGFloat = 0 | ||
|
||
var toRed: CGFloat = 0 | ||
var toGreen: CGFloat = 0 | ||
var toBlue: CGFloat = 0 | ||
var toAlpha: CGFloat = 0 | ||
|
||
fromValue.getRed(&fromRed, green: &fromGreen, blue: &fromBlue, alpha: &fromAlpha) | ||
toValue.getRed(&toRed, green: &toGreen, blue: &toBlue, alpha: &toAlpha) | ||
|
||
let red = CGFloat.interpolate(from: fromRed, to: toRed, withProgress: progress) | ||
let green = CGFloat.interpolate(from: fromGreen, to: toGreen, withProgress: progress) | ||
let blue = CGFloat.interpolate(from: fromBlue, to: toBlue, withProgress: progress) | ||
let alpha = CGFloat.interpolate(from: fromAlpha, to: toAlpha, withProgress: progress) | ||
|
||
return UIColor(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
public static func objectify(value: UIColor) -> AnyObject { | ||
return value | ||
} | ||
} |
Oops, something went wrong.