Commit 5ee12903 by Daniel Dahan

development: updated MotionAnimation documentation

parent d209ff5d
...@@ -94,7 +94,7 @@ public enum MotionAnimation { ...@@ -94,7 +94,7 @@ public enum MotionAnimation {
extension CALayer { extension CALayer {
/** /**
A method that accepts CAAnimation objects and executes them on the A function that accepts CAAnimation objects and executes them on the
view's backing layer. view's backing layer.
- Parameter animation: A CAAnimation instance. - Parameter animation: A CAAnimation instance.
*/ */
...@@ -103,7 +103,7 @@ extension CALayer { ...@@ -103,7 +103,7 @@ extension CALayer {
} }
/** /**
A method that accepts CAAnimation objects and executes them on the A function that accepts CAAnimation objects and executes them on the
view's backing layer. view's backing layer.
- Parameter animation: A CAAnimation instance. - Parameter animation: A CAAnimation instance.
*/ */
...@@ -125,7 +125,7 @@ extension CALayer { ...@@ -125,7 +125,7 @@ extension CALayer {
} }
/** /**
A delegation method that is executed when the backing layer stops A delegation function that is executed when the backing layer stops
running an animation. running an animation.
- Parameter animation: The CAAnimation instance that stopped running. - Parameter animation: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped - Parameter flag: A boolean that indicates if the animation stopped
...@@ -158,14 +158,29 @@ extension CALayer { ...@@ -158,14 +158,29 @@ extension CALayer {
removeAnimation(forKey: k) removeAnimation(forKey: k)
} }
/**
A function that accepts a list of MotionAnimation values and executes them.
- Parameter animations: A list of MotionAnimation values.
*/
open func motion(_ animations: MotionAnimation...) { open func motion(_ animations: MotionAnimation...) {
motion(animations) motion(animations)
} }
/**
A function that accepts an Array of MotionAnimation values and executes them.
- Parameter animations: An Array of MotionAnimation values.
*/
open func motion(_ animations: [MotionAnimation]) { open func motion(_ animations: [MotionAnimation]) {
motion(delay: 0, duration: 0.25, timingFunction: .easeInEaseOut, animations: animations) motion(delay: 0, duration: 0.25, timingFunction: .easeInEaseOut, animations: animations)
} }
/**
A function that executes an Array of MotionAnimation values.
- Parameter delay: The animation delay TimeInterval.
- Parameter duration: The animation duration TimeInterval.
- Parameter timingFunction: The animation MotionAnimationTimingFunction.
- Parameter animations: An Array of MotionAnimations.
*/
fileprivate func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) { fileprivate func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
var t = delay var t = delay
...@@ -186,8 +201,8 @@ extension CALayer { ...@@ -186,8 +201,8 @@ extension CALayer {
var tf = timingFunction var tf = timingFunction
var d = duration var d = duration
var w: CGFloat = s.width var w: CGFloat = s.bounds.width
var h: CGFloat = s.height var h: CGFloat = s.bounds.height
for v in animations { for v in animations {
switch v { switch v {
...@@ -300,23 +315,53 @@ extension CALayer { ...@@ -300,23 +315,53 @@ extension CALayer {
extension CALayer: CAAnimationDelegate {} extension CALayer: CAAnimationDelegate {}
extension UIView { extension UIView {
/// Computes the rotation of the view.
open var motionRotationAngle: Double {
return Double(atan2f(Float(transform.b), Float(transform.a))) * 180 / M_PI
}
/// Computes the scale X axis value of the view.
open var motionScaleX: CGFloat {
return transform.a
}
/// Computes the scale Y axis value of the view.
open var motionScaleY: CGFloat {
return transform.b
}
/** /**
A method that accepts CAAnimation objects and executes them on the A function that accepts CAAnimation objects and executes them on the
view's backing layer. view's backing layer.
- Parameter animation: A CAAnimation instance. - Parameter animations: A list of CAAnimations.
*/ */
open func animate(_ animations: CAAnimation...) { open func animate(_ animations: CAAnimation...) {
layer.animate(animations) layer.animate(animations)
} }
/**
A function that accepts an Array of CAAnimation objects and executes
them on the view's backing layer.
- Parameter animations: An Array of CAAnimations.
*/
open func animate(_ animations: [CAAnimation]) { open func animate(_ animations: [CAAnimation]) {
layer.animate(animations) layer.animate(animations)
} }
/**
A function that accepts a list of MotionAnimation values and executes
them on the view's backing layer.
- Parameter animations: A list of MotionAnimation values.
*/
open func motion(_ animations: MotionAnimation...) { open func motion(_ animations: MotionAnimation...) {
layer.motion(animations) layer.motion(animations)
} }
/**
A function that accepts an Array of MotionAnimation values and executes
them on the view's backing layer.
- Parameter animations: An Array of MotionAnimation values.
*/
open func motion(_ animations: [MotionAnimation]) { open func motion(_ animations: [MotionAnimation]) {
layer.motion(animations) layer.motion(animations)
} }
...@@ -461,7 +506,7 @@ extension Motion { ...@@ -461,7 +506,7 @@ extension Motion {
*/ */
public static func scale(to scale: Double) -> CABasicAnimation { public static func scale(to scale: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scale) let animation = CABasicAnimation(keyPath: .scale)
animation.toValue = scale as NSNumber animation.toValue = NSNumber(floatLiteral: scale)
return animation return animation
} }
...@@ -472,7 +517,7 @@ extension Motion { ...@@ -472,7 +517,7 @@ extension Motion {
*/ */
public static func scaleX(to scale: Double) -> CABasicAnimation { public static func scaleX(to scale: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleX) let animation = CABasicAnimation(keyPath: .scaleX)
animation.toValue = scale as NSNumber animation.toValue = NSNumber(floatLiteral: scale)
return animation return animation
} }
...@@ -483,7 +528,7 @@ extension Motion { ...@@ -483,7 +528,7 @@ extension Motion {
*/ */
public static func scaleY(to scale: Double) -> CABasicAnimation { public static func scaleY(to scale: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleY) let animation = CABasicAnimation(keyPath: .scaleY)
animation.toValue = scale as NSNumber animation.toValue = NSNumber(floatLiteral: scale)
return animation return animation
} }
...@@ -494,7 +539,7 @@ extension Motion { ...@@ -494,7 +539,7 @@ extension Motion {
*/ */
public static func scaleZ(to scale: Double) -> CABasicAnimation { public static func scaleZ(to scale: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleZ) let animation = CABasicAnimation(keyPath: .scaleZ)
animation.toValue = scale as NSNumber animation.toValue = NSNumber(floatLiteral: scale)
return animation return animation
} }
...@@ -516,7 +561,7 @@ extension Motion { ...@@ -516,7 +561,7 @@ extension Motion {
*/ */
public static func translateX(to translation: CGFloat) -> CABasicAnimation { public static func translateX(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationX) let animation = CABasicAnimation(keyPath: .translationX)
animation.toValue = translation as NSNumber animation.toValue = NSNumber(floatLiteral: Double(translation))
return animation return animation
} }
...@@ -527,7 +572,7 @@ extension Motion { ...@@ -527,7 +572,7 @@ extension Motion {
*/ */
public static func translateY(to translation: CGFloat) -> CABasicAnimation { public static func translateY(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationY) let animation = CABasicAnimation(keyPath: .translationY)
animation.toValue = translation as NSNumber animation.toValue = NSNumber(floatLiteral: Double(translation))
return animation return animation
} }
...@@ -538,7 +583,7 @@ extension Motion { ...@@ -538,7 +583,7 @@ extension Motion {
*/ */
public static func translateZ(to translation: CGFloat) -> CABasicAnimation { public static func translateZ(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationZ) let animation = CABasicAnimation(keyPath: .translationZ)
animation.toValue = translation as NSNumber animation.toValue = NSNumber(floatLiteral: Double(translation))
return animation return animation
} }
......
...@@ -42,11 +42,6 @@ fileprivate struct MotionTransitionItemController { ...@@ -42,11 +42,6 @@ fileprivate struct MotionTransitionItemController {
fileprivate var delegate: MotionTransitionAnimator fileprivate var delegate: MotionTransitionAnimator
} }
fileprivate func getRotationInDegrees(view: UIView) -> Double {
let radians = Double(atan2f(Float(view.transform.b), Float(view.transform.a)))
return ceil(radians * 180 / M_PI)
}
extension UIViewController { extension UIViewController {
/// MaterialLayer Reference. /// MaterialLayer Reference.
fileprivate var motionTransition: MotionTransitionItemController { fileprivate var motionTransition: MotionTransitionItemController {
...@@ -373,7 +368,7 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator { ...@@ -373,7 +368,7 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
snapshotChildAnimations.append(Motion.position(x: w / 2, y: h / 2)) snapshotChildAnimations.append(Motion.position(x: w / 2, y: h / 2))
snapshotChildAnimations.append(sizeAnimation) snapshotChildAnimations.append(sizeAnimation)
snapshotAnimations.append(Motion.rotate(angle: getRotationInDegrees(view: toView))) snapshotAnimations.append(Motion.rotate(angle: toView.motionRotationAngle))
let cornerRadiusAnimation = Motion.corner(radius: toView.cornerRadius) let cornerRadiusAnimation = Motion.corner(radius: toView.cornerRadius)
snapshotAnimations.append(cornerRadiusAnimation) snapshotAnimations.append(cornerRadiusAnimation)
...@@ -487,7 +482,7 @@ open class MotionTransitionDismissedAnimator: MotionTransitionAnimator { ...@@ -487,7 +482,7 @@ open class MotionTransitionDismissedAnimator: MotionTransitionAnimator {
snapshotChildAnimations.append(Motion.position(x: w / 2, y: h / 2)) snapshotChildAnimations.append(Motion.position(x: w / 2, y: h / 2))
snapshotChildAnimations.append(sizeAnimation) snapshotChildAnimations.append(sizeAnimation)
snapshotAnimations.append(Motion.rotate(angle: getRotationInDegrees(view: toView))) snapshotAnimations.append(Motion.rotate(angle: toView.motionRotationAngle))
let cornerRadiusAnimation = Motion.corner(radius: toView.cornerRadius) let cornerRadiusAnimation = Motion.corner(radius: toView.cornerRadius)
snapshotAnimations.append(cornerRadiusAnimation) snapshotAnimations.append(cornerRadiusAnimation)
......
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