Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
2.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Nov 5, 2015
1 parent 0b631fe commit 8c2400e
Show file tree
Hide file tree
Showing 77 changed files with 1,207 additions and 1,905 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# OS X

.DS_Store

# Xcode

build/
Expand Down
Binary file modified Assets/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015 David Roman
Copyright (c) 2015 IFTTT Inc
Copyright (c) 2015 David Román

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 8 additions & 7 deletions Popsicle.podspec
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
689 changes: 175 additions & 514 deletions Popsicle.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

31 changes: 22 additions & 9 deletions Popsicle.xcodeproj/xcshareddata/xcschemes/Popsicle.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "75CE051E1ACA133B008B893D"
BlueprintIdentifier = "D5FBF5391BE65BB500F3CB79"
BuildableName = "Popsicle.framework"
BlueprintName = "Popsicle"
ReferencedContainer = "container:Popsicle.xcodeproj">
Expand All @@ -23,35 +23,48 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5FBF5431BE65BB500F3CB79"
BuildableName = "PopsicleTests.xctest"
BlueprintName = "PopsicleTests"
ReferencedContainer = "container:Popsicle.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "75CE051E1ACA133B008B893D"
BlueprintIdentifier = "D5FBF5391BE65BB500F3CB79"
BuildableName = "Popsicle.framework"
BlueprintName = "Popsicle"
ReferencedContainer = "container:Popsicle.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "75CE051E1ACA133B008B893D"
BlueprintIdentifier = "D5FBF5391BE65BB500F3CB79"
BuildableName = "Popsicle.framework"
BlueprintName = "Popsicle"
ReferencedContainer = "container:Popsicle.xcodeproj">
Expand All @@ -61,15 +74,15 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "75CE051E1ACA133B008B893D"
BlueprintIdentifier = "D5FBF5391BE65BB500F3CB79"
BuildableName = "Popsicle.framework"
BlueprintName = "Popsicle"
ReferencedContainer = "container:Popsicle.xcodeproj">
Expand Down
62 changes: 62 additions & 0 deletions Popsicle/EasingFunction.swift
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))
}
4 changes: 2 additions & 2 deletions Popsicle/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>me.davidroman.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>2.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
161 changes: 161 additions & 0 deletions Popsicle/Interpolable.swift
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
}
}
Loading

0 comments on commit 8c2400e

Please sign in to comment.