Commit aad47c6d by Daniel Dahan

added first pass at Spring animmations

parent a8b1aa0e
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
96AEB6AF1EE4610F009A3BE0 /* MatchPreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB68B1EE4610F009A3BE0 /* MatchPreprocessor.swift */; }; 96AEB6AF1EE4610F009A3BE0 /* MatchPreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB68B1EE4610F009A3BE0 /* MatchPreprocessor.swift */; };
96AEB6B01EE4610F009A3BE0 /* SourcePreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB68C1EE4610F009A3BE0 /* SourcePreprocessor.swift */; }; 96AEB6B01EE4610F009A3BE0 /* SourcePreprocessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB68C1EE4610F009A3BE0 /* SourcePreprocessor.swift */; };
96E49A401EEA08F8006D5A93 /* MotionTransitionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */; }; 96E49A401EEA08F8006D5A93 /* MotionTransitionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */; };
96F8905B1F045099004BEB1A /* MotionCAAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96F8905A1F045099004BEB1A /* MotionCAAnimation.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
...@@ -83,6 +84,7 @@ ...@@ -83,6 +84,7 @@
96C98DE21E43809D00B22906 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; }; 96C98DE21E43809D00B22906 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
96C98DED1E438A5700B22906 /* Motion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Motion.h; sourceTree = "<group>"; }; 96C98DED1E438A5700B22906 /* Motion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Motion.h; sourceTree = "<group>"; };
96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionTransitionObserver.swift; sourceTree = "<group>"; }; 96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionTransitionObserver.swift; sourceTree = "<group>"; };
96F8905A1F045099004BEB1A /* MotionCAAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionCAAnimation.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -173,6 +175,7 @@ ...@@ -173,6 +175,7 @@
96AEB67B1EE4610F009A3BE0 /* MotionTransition.swift */, 96AEB67B1EE4610F009A3BE0 /* MotionTransition.swift */,
96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */, 96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */,
96AEB67D1EE4610F009A3BE0 /* MotionPlugin.swift */, 96AEB67D1EE4610F009A3BE0 /* MotionPlugin.swift */,
96F8905A1F045099004BEB1A /* MotionCAAnimation.swift */,
96AEB6641EE4610F009A3BE0 /* Animator */, 96AEB6641EE4610F009A3BE0 /* Animator */,
96AEB66D1EE4610F009A3BE0 /* Extensions */, 96AEB66D1EE4610F009A3BE0 /* Extensions */,
96AEB6861EE4610F009A3BE0 /* Preprocessors */, 96AEB6861EE4610F009A3BE0 /* Preprocessors */,
...@@ -267,6 +270,7 @@ ...@@ -267,6 +270,7 @@
96AEB6931EE4610F009A3BE0 /* TransitionPreprocessor.swift in Sources */, 96AEB6931EE4610F009A3BE0 /* TransitionPreprocessor.swift in Sources */,
96AEB68F1EE4610F009A3BE0 /* MotionDefaultAnimator.swift in Sources */, 96AEB68F1EE4610F009A3BE0 /* MotionDefaultAnimator.swift in Sources */,
96AEB69D1EE4610F009A3BE0 /* Motion.swift in Sources */, 96AEB69D1EE4610F009A3BE0 /* Motion.swift in Sources */,
96F8905B1F045099004BEB1A /* MotionCAAnimation.swift in Sources */,
963150D61EE51C7A002B0D42 /* MotionAnimation.swift in Sources */, 963150D61EE51C7A002B0D42 /* MotionAnimation.swift in Sources */,
968989DE1EE6633E003B8F3D /* MotionAnimator.swift in Sources */, 968989DE1EE6633E003B8F3D /* MotionAnimator.swift in Sources */,
968989B91EE5B34B003B8F3D /* MotionHasInsertOrder.swift in Sources */, 968989B91EE5B34B003B8F3D /* MotionHasInsertOrder.swift in Sources */,
......
...@@ -160,103 +160,109 @@ fileprivate extension CALayer { ...@@ -160,103 +160,109 @@ fileprivate extension CALayer {
let d: TimeInterval = targetState.duration ?? duration let d: TimeInterval = targetState.duration ?? duration
if let v = targetState.backgroundColor { if let v = targetState.backgroundColor {
let a = MotionBasicAnimation.background(color: UIColor(cgColor: v)) let a = MotionCAAnimation.background(color: UIColor(cgColor: v))
a.fromValue = s.backgroundColor a.fromValue = s.backgroundColor
anims.append(a) anims.append(a)
} }
if let v = targetState.borderColor { if let v = targetState.borderColor {
let a = MotionBasicAnimation.border(color: UIColor(cgColor: v)) let a = MotionCAAnimation.border(color: UIColor(cgColor: v))
a.fromValue = s.borderColor a.fromValue = s.borderColor
anims.append(a) anims.append(a)
} }
if let v = targetState.borderWidth { if let v = targetState.borderWidth {
let a = MotionBasicAnimation.border(width: v) let a = MotionCAAnimation.border(width: v)
a.fromValue = NSNumber(floatLiteral: Double(s.borderWidth)) a.fromValue = NSNumber(floatLiteral: Double(s.borderWidth))
anims.append(a) anims.append(a)
} }
if let v = targetState.cornerRadius { if let v = targetState.cornerRadius {
let a = MotionBasicAnimation.corner(radius: v) let a = MotionCAAnimation.corner(radius: v)
a.fromValue = NSNumber(floatLiteral: Double(s.cornerRadius)) a.fromValue = NSNumber(floatLiteral: Double(s.cornerRadius))
anims.append(a) anims.append(a)
} }
if let v = targetState.transform { if let v = targetState.transform {
let a = MotionBasicAnimation.transform(v) let a = MotionCAAnimation.transform(v)
a.fromValue = NSValue(caTransform3D: s.transform) a.fromValue = NSValue(caTransform3D: s.transform)
anims.append(a) anims.append(a)
} }
if let v = targetState.spin { if let v = targetState.spin {
var a = MotionBasicAnimation.spinX(v.0) var a = MotionCAAnimation.spinX(v.0)
a.fromValue = NSNumber(floatLiteral: 0) a.fromValue = NSNumber(floatLiteral: 0)
anims.append(a) anims.append(a)
a = MotionBasicAnimation.spinY(v.1) a = MotionCAAnimation.spinY(v.1)
a.fromValue = NSNumber(floatLiteral: 0) a.fromValue = NSNumber(floatLiteral: 0)
anims.append(a) anims.append(a)
a = MotionBasicAnimation.spinZ(v.2) a = MotionCAAnimation.spinZ(v.2)
a.fromValue = NSNumber(floatLiteral: 0) a.fromValue = NSNumber(floatLiteral: 0)
anims.append(a) anims.append(a)
} }
if let v = targetState.position { if let v = targetState.position {
let a = MotionBasicAnimation.position(v) let a = MotionCAAnimation.position(v)
a.fromValue = NSValue(cgPoint: s.position) a.fromValue = NSValue(cgPoint: s.position)
anims.append(a) anims.append(a)
} }
if let v = targetState.opacity { if let v = targetState.opacity {
let a = MotionBasicAnimation.fade(v) let a = MotionCAAnimation.fade(v)
a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1) a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1)
anims.append(a) anims.append(a)
} }
if let v = targetState.zPosition { if let v = targetState.zPosition {
let a = MotionBasicAnimation.zPosition(v) let a = MotionCAAnimation.zPosition(v)
a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.zPosition.rawValue) ?? NSNumber(floatLiteral: 0) a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.zPosition.rawValue) ?? NSNumber(floatLiteral: 0)
anims.append(a) anims.append(a)
} }
if let v = targetState.size { if let v = targetState.size {
let a = MotionBasicAnimation.size(v) let a = MotionCAAnimation.size(v)
a.fromValue = NSValue(cgSize: s.bounds.size) a.fromValue = NSValue(cgSize: s.bounds.size)
anims.append(a) anims.append(a)
} }
if let v = targetState.shadowPath { if let v = targetState.shadowPath {
let a = MotionBasicAnimation.shadow(path: v) let a = MotionCAAnimation.shadow(path: v)
a.fromValue = s.shadowPath a.fromValue = s.shadowPath
anims.append(a) anims.append(a)
} }
if let v = targetState.shadowColor { if let v = targetState.shadowColor {
let a = MotionBasicAnimation.shadow(color: UIColor(cgColor: v)) let a = MotionCAAnimation.shadow(color: UIColor(cgColor: v))
a.fromValue = s.shadowColor a.fromValue = s.shadowColor
anims.append(a) anims.append(a)
} }
if let v = targetState.shadowOffset { if let v = targetState.shadowOffset {
let a = MotionBasicAnimation.shadow(offset: v) let a = MotionCAAnimation.shadow(offset: v)
a.fromValue = NSValue(cgSize: s.shadowOffset) a.fromValue = NSValue(cgSize: s.shadowOffset)
anims.append(a) anims.append(a)
} }
if let v = targetState.shadowOpacity { if let v = targetState.shadowOpacity {
let a = MotionBasicAnimation.shadow(opacity: v) let a = MotionCAAnimation.shadow(opacity: v)
a.fromValue = NSNumber(floatLiteral: Double(s.shadowOpacity)) a.fromValue = NSNumber(floatLiteral: Double(s.shadowOpacity))
anims.append(a) anims.append(a)
} }
if let v = targetState.shadowRadius { if let v = targetState.shadowRadius {
let a = MotionBasicAnimation.shadow(radius: v) let a = MotionCAAnimation.shadow(radius: v)
a.fromValue = NSNumber(floatLiteral: Double(s.shadowRadius)) a.fromValue = NSNumber(floatLiteral: Double(s.shadowRadius))
anims.append(a) anims.append(a)
} }
if #available(iOS 9.0, *), let (stiffness, damping) = targetState.spring {
for i in 0..<anims.count where "cornerRadius" != anims[i].keyPath {
anims[i] = MotionCAAnimation.convert(basic: anims[i], stiffness: stiffness, damping: damping)
}
}
let g = Motion.animate(group: anims, duration: d) let g = Motion.animate(group: anims, duration: d)
g.fillMode = MotionAnimationFillModeToValue(mode: .forwards) g.fillMode = MotionAnimationFillModeToValue(mode: .forwards)
g.isRemovedOnCompletion = false g.isRemovedOnCompletion = false
......
...@@ -447,267 +447,3 @@ extension MotionAnimation { ...@@ -447,267 +447,3 @@ extension MotionAnimation {
} }
} }
} }
public enum MotionAnimationKeyPath: String {
case backgroundColor
case barTintColor
case borderColor
case borderWidth
case cornerRadius
case transform
case rotate = "transform.rotation"
case rotateX = "transform.rotation.x"
case rotateY = "transform.rotation.y"
case rotateZ = "transform.rotation.z"
case scale = "transform.scale"
case scaleX = "transform.scale.x"
case scaleY = "transform.scale.y"
case scaleZ = "transform.scale.z"
case translation = "transform.translation"
case translationX = "transform.translation.x"
case translationY = "transform.translation.y"
case translationZ = "transform.translation.z"
case position
case opacity
case zPosition
case width = "bounds.size.width"
case height = "bounds.size.height"
case size = "bounds.size"
case shadowPath
case shadowColor
case shadowOffset
case shadowOpacity
case shadowRadius
}
extension CABasicAnimation {
/**
A convenience initializer that takes a given MotionAnimationKeyPath.
- Parameter keyPath: An MotionAnimationKeyPath.
*/
public convenience init(keyPath: MotionAnimationKeyPath) {
self.init(keyPath: keyPath.rawValue)
}
}
public struct MotionBasicAnimation {
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public static func background(color: UIColor) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .backgroundColor)
a.toValue = color.cgColor
return a
}
/**
Creates a CABasicAnimation for the barTintColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public static func barTint(color: UIColor) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .barTintColor)
a.toValue = color.cgColor
return a
}
/**
Creates a CABasicAnimation for the borderColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public static func border(color: UIColor) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .borderColor)
a.toValue = color.cgColor
return a
}
/**
Creates a CABasicAnimation for the borderWidth key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func border(width: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .borderWidth)
a.toValue = NSNumber(floatLiteral: Double(width))
return a
}
/**
Creates a CABasicAnimation for the cornerRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func corner(radius: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .cornerRadius)
a.toValue = NSNumber(floatLiteral: Double(radius))
return a
}
/**
Creates a CABasicAnimation for the transform key path.
- Parameter _ t: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
public static func transform(_ t: CATransform3D) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .transform)
a.toValue = NSValue(caTransform3D: t)
return a
}
/**
Creates a CABasicAnimation for the transform.rotate.x key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public static func spinX(_ rotations: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .rotateX)
a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return a
}
/**
Creates a CABasicAnimation for the transform.rotate.y key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public static func spinY(_ rotations: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .rotateY)
a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return a
}
/**
Creates a CABasicAnimation for the transform.rotate.z key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public static func spinZ(_ rotations: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .rotateZ)
a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return a
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter _ point: A CGPoint.
- Returns: A CABasicAnimation.
*/
public static func position(_ point: CGPoint) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .position)
a.toValue = NSValue(cgPoint: point)
return a
}
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter _ opacity: A Double.
- Returns: A CABasicAnimation.
*/
public static func fade(_ opacity: Double) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .opacity)
a.toValue = NSNumber(floatLiteral: opacity)
return a
}
/**
Creates a CABasicaAnimation for the zPosition key path.
- Parameter _ position: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func zPosition(_ position: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .zPosition)
a.toValue = NSNumber(value: Double(position))
return a
}
/**
Creates a CABasicaAnimation for the width key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func width(_ width: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .width)
a.toValue = NSNumber(floatLiteral: Double(width))
return a
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter height: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func height(_ height: CGFloat) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .height)
a.toValue = NSNumber(floatLiteral: Double(height))
return a
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter size: A CGSize.
- Returns: A CABasicAnimation.
*/
public static func size(_ size: CGSize) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: .size)
a.toValue = NSValue(cgSize: size)
return a
}
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public static func shadow(path: CGPath) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowPath)
animation.toValue = path
return animation
}
/**
Creates a CABasicAnimation for the shadowColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public static func shadow(color: UIColor) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowColor)
animation.toValue = color.cgColor
return animation
}
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: A CGSize.
- Returns: A CABasicAnimation.
*/
public static func shadow(offset: CGSize) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowOffset)
animation.toValue = NSValue(cgSize: offset)
return animation
}
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: A Float.
- Returns: A CABasicAnimation.
*/
public static func shadow(opacity: Float) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowOpacity)
animation.toValue = NSNumber(floatLiteral: Double(opacity))
return animation
}
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func shadow(radius: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowRadius)
animation.toValue = NSNumber(floatLiteral: Double(radius))
return animation
}
}
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public enum MotionAnimationKeyPath: String {
case backgroundColor
case borderColor
case borderWidth
case cornerRadius
case transform
case rotate = "transform.rotation"
case rotateX = "transform.rotation.x"
case rotateY = "transform.rotation.y"
case rotateZ = "transform.rotation.z"
case scale = "transform.scale"
case scaleX = "transform.scale.x"
case scaleY = "transform.scale.y"
case scaleZ = "transform.scale.z"
case translation = "transform.translation"
case translationX = "transform.translation.x"
case translationY = "transform.translation.y"
case translationZ = "transform.translation.z"
case position
case opacity
case zPosition
case width = "bounds.size.width"
case height = "bounds.size.height"
case size = "bounds.size"
case shadowPath
case shadowColor
case shadowOffset
case shadowOpacity
case shadowRadius
}
extension CABasicAnimation {
/**
A convenience initializer that takes a given MotionAnimationKeyPath.
- Parameter keyPath: An MotionAnimationKeyPath.
*/
public convenience init(keyPath: MotionAnimationKeyPath) {
self.init(keyPath: keyPath.rawValue)
}
}
public struct MotionCAAnimation {}
fileprivate extension MotionCAAnimation {
/**
Creates a CABasicAnimation.
- Parameter keyPath: A MotionAnimationKeyPath.
- Parameter toValue: An Any value that is the end state of the animation.
*/
static func createAnimation(keyPath: MotionAnimationKeyPath, toValue: Any) -> CABasicAnimation {
let a = CABasicAnimation(keyPath: keyPath)
a.toValue = toValue
return a
}
}
@available(iOS 9.0, *)
internal extension MotionCAAnimation {
/**
Converts a CABasicAnimation to a CASpringAnimation.
- Parameter basic: A CABasicAnimation.
- Parameter stiffness: A CGFloat.
- Parameter damping: A CGFloat.
*/
static func convert(basic: CABasicAnimation, stiffness: CGFloat, damping: CGFloat) -> CASpringAnimation {
let a = CASpringAnimation(keyPath: basic.keyPath)
a.fromValue = basic.fromValue
a.toValue = basic.toValue
a.stiffness = stiffness
a.damping = damping
a.duration = a.settlingDuration * 0.9
return a
}
}
public extension MotionCAAnimation {
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
static func background(color: UIColor) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .backgroundColor, toValue: color.cgColor)
}
/**
Creates a CABasicAnimation for the borderColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
static func border(color: UIColor) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .borderColor, toValue: color.cgColor)
}
/**
Creates a CABasicAnimation for the borderWidth key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func border(width: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .borderWidth, toValue: NSNumber(floatLiteral: Double(width)))
}
/**
Creates a CABasicAnimation for the cornerRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func corner(radius: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .cornerRadius, toValue: NSNumber(floatLiteral: Double(radius)))
}
/**
Creates a CABasicAnimation for the transform key path.
- Parameter _ t: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
static func transform(_ t: CATransform3D) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .transform, toValue: NSValue(caTransform3D: t))
}
/**
Creates a CABasicAnimation for the transform.rotate.x key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
static func spinX(_ rotations: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .rotateX, toValue: NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations)))
}
/**
Creates a CABasicAnimation for the transform.rotate.y key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
static func spinY(_ rotations: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .rotateY, toValue: NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations)))
}
/**
Creates a CABasicAnimation for the transform.rotate.z key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
static func spinZ(_ rotations: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .rotateZ, toValue: NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations)))
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter _ point: A CGPoint.
- Returns: A CABasicAnimation.
*/
static func position(_ point: CGPoint) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .position, toValue: NSValue(cgPoint: point))
}
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter _ opacity: A Double.
- Returns: A CABasicAnimation.
*/
static func fade(_ opacity: Double) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .opacity, toValue: NSNumber(floatLiteral: opacity))
}
/**
Creates a CABasicaAnimation for the zPosition key path.
- Parameter _ position: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func zPosition(_ position: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .zPosition, toValue: NSNumber(value: Double(position)))
}
/**
Creates a CABasicaAnimation for the width key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func width(_ width: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .width, toValue: NSNumber(floatLiteral: Double(width)))
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter height: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func height(_ height: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .height, toValue: NSNumber(floatLiteral: Double(height)))
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter size: A CGSize.
- Returns: A CABasicAnimation.
*/
static func size(_ size: CGSize) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .size, toValue: NSValue(cgSize: size))
}
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
static func shadow(path: CGPath) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .shadowPath, toValue: path)
}
/**
Creates a CABasicAnimation for the shadowColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
static func shadow(color: UIColor) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .shadowColor, toValue: color.cgColor)
}
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: A CGSize.
- Returns: A CABasicAnimation.
*/
static func shadow(offset: CGSize) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .shadowOffset, toValue: NSValue(cgSize: offset))
}
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: A Float.
- Returns: A CABasicAnimation.
*/
static func shadow(opacity: Float) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .shadowOpacity, toValue: NSNumber(floatLiteral: Double(opacity)))
}
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
static func shadow(radius: CGFloat) -> CABasicAnimation {
return MotionCAAnimation.createAnimation(keyPath: .shadowRadius, toValue: NSNumber(floatLiteral: Double(radius)))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment