Commit 5dc54456 by Daniel Dahan

added clean functions for current transition properties

parent 21a473d7
...@@ -52,18 +52,18 @@ open class MotionController: NSObject, MotionSubscriber { ...@@ -52,18 +52,18 @@ open class MotionController: NSObject, MotionSubscriber {
} }
/// A reference to the animation duration. /// A reference to the animation duration.
fileprivate var animationDuration: TimeInterval = 0 fileprivate var transitionDuration: TimeInterval = 0
/** /**
A reference to the animation total duration, A reference to the animation total duration,
which is the total running animation time. which is the total running animation time.
*/ */
fileprivate var animationTotalDuration: TimeInterval = 0 fileprivate var transitionTotalDuration: TimeInterval = 0
/// A reference to the animation start time. /// A reference to the animation start time.
fileprivate var animationStartTime: TimeInterval? { fileprivate var transitionStartTime: TimeInterval? {
didSet { didSet {
guard nil != animationStartTime else { guard nil != transitionStartTime else {
displayLink = nil displayLink = nil
return return
} }
...@@ -77,7 +77,7 @@ open class MotionController: NSObject, MotionSubscriber { ...@@ -77,7 +77,7 @@ open class MotionController: NSObject, MotionSubscriber {
} }
/// A reference to the animation elapsed time. /// A reference to the animation elapsed time.
open fileprivate(set) var animationElapsedTime: TimeInterval = 0 { open fileprivate(set) var transitionElapsedTime: TimeInterval = 0 {
didSet { didSet {
guard isTransitioning else { guard isTransitioning else {
return return
...@@ -107,8 +107,11 @@ open class MotionController: NSObject, MotionSubscriber { ...@@ -107,8 +107,11 @@ open class MotionController: NSObject, MotionSubscriber {
return nil == displayLink return nil == displayLink
} }
/// UIKit's supplied transition container. /// Transition container.
open fileprivate(set) var transitionContainer: UIView! open fileprivate(set) var transitionContainer: UIView!
/// An Array of from and to view paris to be animated.
open fileprivate(set) var transitionParis = [(fromViews: [UIView], toViews: [UIView])]()
} }
extension MotionController { extension MotionController {
...@@ -122,28 +125,28 @@ extension MotionController { ...@@ -122,28 +125,28 @@ extension MotionController {
return return
} }
guard 0 < animationDuration else { guard 0 < transitionDuration else {
return return
} }
guard let v = animationStartTime else { guard let v = transitionStartTime else {
return return
} }
var elapsedTime = CACurrentMediaTime() - v var elapsedTime = CACurrentMediaTime() - v
if elapsedTime > animationDuration { if elapsedTime > transitionDuration {
animationElapsedTime = isFinished ? 1 : 0 transitionElapsedTime = isFinished ? 1 : 0
completeTransition() completeTransition()
} else { } else {
elapsedTime = elapsedTime / animationDuration elapsedTime = elapsedTime / transitionDuration
if !isFinished { if !isFinished {
elapsedTime = 1 - elapsedTime elapsedTime = 1 - elapsedTime
} }
animationElapsedTime = max(0, min(1, elapsedTime)) transitionElapsedTime = max(0, min(1, elapsedTime))
} }
} }
} }
...@@ -151,13 +154,13 @@ extension MotionController { ...@@ -151,13 +154,13 @@ extension MotionController {
extension MotionController { extension MotionController {
fileprivate func updateMotionObservers() { fileprivate func updateMotionObservers() {
for v in observers { for v in observers {
v.update(elapsedTime: animationElapsedTime) v.update(elapsedTime: transitionElapsedTime)
} }
} }
/// Updates the motion animators. /// Updates the motion animators.
fileprivate func updateMotionAnimators() { fileprivate func updateMotionAnimators() {
let elapsedTime = animationElapsedTime * animationTotalDuration let elapsedTime = transitionElapsedTime * transitionTotalDuration
for v in animators { for v in animators {
v.seekTo(elapsedTime: elapsedTime) v.seekTo(elapsedTime: elapsedTime)
...@@ -181,6 +184,8 @@ extension MotionController { ...@@ -181,6 +184,8 @@ extension MotionController {
/// Cleans the transition values. /// Cleans the transition values.
fileprivate func cleanTransitionValues() { fileprivate func cleanTransitionValues() {
animationStartTime = nil transitionStartTime = nil
transitionElapsedTime = 0
transitionTotalDuration = 0
} }
} }
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