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