Commit a9620296 by Daniel Dahan

development: added delay, duration, and timingFunction to motionAnimations for…

development: added delay, duration, and timingFunction to motionAnimations for view controller transitions
parent 3fe5ad8d
...@@ -119,10 +119,6 @@ open class BottomNavigationController: UITabBarController, UITabBarControllerDel ...@@ -119,10 +119,6 @@ open class BottomNavigationController: UITabBarController, UITabBarControllerDel
/// Handles transitions when tabBarItems are pressed. /// Handles transitions when tabBarItems are pressed.
open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard nil != fromVC, nil != toVC else {
return nil
}
return .fade == motionTransition ? FadeMotionTransition() : nil return .fade == motionTransition ? FadeMotionTransition() : nil
} }
......
...@@ -53,6 +53,9 @@ public enum MotionAnimationKeyPath: String { ...@@ -53,6 +53,9 @@ public enum MotionAnimationKeyPath: String {
} }
public enum MotionAnimation { public enum MotionAnimation {
case delay(CGFloat)
case timingFunction(MotionAnimationTimingFunction)
case duration(CGFloat)
case custom(CABasicAnimation) case custom(CABasicAnimation)
case backgroundColor(UIColor) case backgroundColor(UIColor)
case corners(CGFloat) case corners(CGFloat)
...@@ -141,7 +144,7 @@ extension CALayer { ...@@ -141,7 +144,7 @@ extension CALayer {
} }
open func motion(animations: [MotionAnimation]) { open func motion(animations: [MotionAnimation]) {
motion(duration: 0.15, animations: animations) motion(duration: 0.25, animations: animations)
} }
open func motion(duration: TimeInterval, animations: MotionAnimation...) { open func motion(duration: TimeInterval, animations: MotionAnimation...) {
...@@ -157,7 +160,7 @@ extension CALayer { ...@@ -157,7 +160,7 @@ extension CALayer {
} }
open func motion(timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) { open func motion(timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
motion(duration: 0.15, animations: animations) motion(duration: 0.25, animations: animations)
} }
open func motion(duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) { open func motion(duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) {
...@@ -165,11 +168,51 @@ extension CALayer { ...@@ -165,11 +168,51 @@ extension CALayer {
} }
open func motion(duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) { open func motion(duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
motion(delay: 0, duration: duration, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, animations: MotionAnimation...) {
motion(delay: delay, animations: animations)
}
open func motion(delay: TimeInterval, animations: [MotionAnimation]) {
motion(delay: delay, duration: 0.25, timingFunction: .easeInEaseOut, animations: animations)
}
open func motion(delay: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) {
motion(delay: delay, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
motion(delay: delay, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, animations: MotionAnimation...) {
motion(delay: delay, duration: duration, timingFunction: .easeInEaseOut, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, animations: [MotionAnimation]) {
motion(delay: delay, duration: duration, timingFunction: .easeInEaseOut, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) {
motion(delay: delay, duration: duration, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
var a = [CABasicAnimation]() var a = [CABasicAnimation]()
var tf = timingFunction
var d = duration
var t = delay
for v in animations { for v in animations {
switch v { switch v {
case let .delay(time):
t = TimeInterval(time)
case let .timingFunction(tFunction):
tf = tFunction
case let .duration(dur):
d = TimeInterval(dur)
case let .custom(animation): case let .custom(animation):
a.append(animation) a.append(animation)
case let .backgroundColor(color): case let .backgroundColor(color):
...@@ -225,55 +268,17 @@ extension CALayer { ...@@ -225,55 +268,17 @@ extension CALayer {
} }
} }
let g = Motion.animate(group: a, duration: duration) Motion.delay(time: t) { [weak self] in
g.fillMode = MotionAnimationFillModeToValue(mode: .forwards)
g.isRemovedOnCompletion = false
g.timingFunction = MotionAnimationTimingFunctionToValue(timingFunction: timingFunction)
animate(animation: g)
}
open func motion(delay: TimeInterval, animations: MotionAnimation...) {
motion(delay: delay, animations: animations)
}
open func motion(delay: TimeInterval, animations: [MotionAnimation]) {
Motion.delay(time: delay) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
s.motion(animations: animations) let g = Motion.animate(group: a, duration: d)
} g.fillMode = MotionAnimationFillModeToValue(mode: .forwards)
} g.isRemovedOnCompletion = false
g.timingFunction = MotionAnimationTimingFunctionToValue(timingFunction: tf)
open func motion(delay: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) {
motion(delay: delay, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
motion(delay: delay, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, animations: MotionAnimation...) {
motion(delay: delay, duration: duration, timingFunction: .easeInEaseOut, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, animations: [MotionAnimation]) {
motion(delay: delay, duration: duration, timingFunction: .easeInEaseOut, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: MotionAnimation...) {
motion(delay: delay, duration: duration, timingFunction: timingFunction, animations: animations)
}
open func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
Motion.delay(time: delay) { [weak self] in
guard let s = self else {
return
}
s.motion(duration: duration, timingFunction: timingFunction, animations: animations) s.animate(animation: g)
} }
} }
} }
......
...@@ -143,34 +143,43 @@ open class SlideMotionTransition: NSObject, UIViewControllerAnimatedTransitionin ...@@ -143,34 +143,43 @@ open class SlideMotionTransition: NSObject, UIViewControllerAnimatedTransitionin
return return
} }
let duration = transitionDuration(using: nil)
if operation == .push {
transitionContext.containerView.addSubview(fromView)
for v in fromView.subviews { switch operation {
if 0 < v.motionIdentifier.utf16.count { case .push:
v.motion(duration: 0.35, animations: v.motionAnimations) for n in fromView.subviews {
if 0 < n.motionIdentifier.utf16.count {
for m in toView.subviews {
if n.motionIdentifier == m.motionIdentifier {
m.motion(duration: duration, animations: m.motionAnimations)
}
}
} }
} }
Motion.delay(time: transitionDuration(using: nil)) { Motion.delay(time: duration) {
transitionContext.containerView.addSubview(toView)
transitionContext.completeTransition(!transitionContext.transitionWasCancelled) transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
} }
}
if operation == .pop {
transitionContext.containerView.addSubview(toView) transitionContext.containerView.addSubview(toView)
case .pop:
for v in toView.subviews { for n in fromView.subviews {
if 0 < v.motionIdentifier.utf16.count { if 0 < n.motionIdentifier.utf16.count {
v.motion(duration: 0.35, animations: [.scale(1), .backgroundColor(.white)]) for m in toView.subviews {
if n.motionIdentifier == m.motionIdentifier {
m.motion(duration: duration, animations: m.motionAnimations)
}
}
} }
} }
Motion.delay(time: transitionDuration(using: nil)) { Motion.delay(time: duration) {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled) transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
} }
transitionContext.containerView.addSubview(toView)
case .none:break
} }
} }
......
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