Skip to content

Commit

Permalink
Added reference if "CAAnimation+ImmediateValue.h".
Browse files Browse the repository at this point in the history
  • Loading branch information
devedbox committed Apr 3, 2017
1 parent 95208aa commit 2bb262f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions AXAnimationChain/Classes/CoreAnimation/AXCoreAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "AXDecayAnimation.h"
#import "AXSpringAnimation.h"
#import "CAAnimation+Convertable.h"
#import "CAAnimation+ImmediateValue.h"
#import "CAMediaTimingFunction+Extends.h"

#endif /* AXCoreAnimation_h */
42 changes: 34 additions & 8 deletions AXAnimationChain/DecayAnimationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class DecayAnimationViewController: UIViewController, UIGestureRecognizerDelegat
let pan = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
pan.delegate = self
animatedView.addGestureRecognizer(pan)

let tap = UITapGestureRecognizer(target: self, action: #selector(handleTagGesture(_:)))
view.addGestureRecognizer(tap)
}

override func didReceiveMemoryWarning() {
Expand All @@ -29,15 +32,38 @@ class DecayAnimationViewController: UIViewController, UIGestureRecognizerDelegat
}

// MARK: Actions.
@objc
private func handleTagGesture(_ genture: UITapGestureRecognizer) {
defer {
animatedView.layer.removeAllAnimations()
}
guard let animationKeys = animatedView.layer.animationKeys() else { return }
for key in animationKeys {
guard let animation = animatedView.layer.animation(forKey: key) as? AXDecayAnimation else { continue }

let beginTime = animation.beginTime
let timeOffset = animation.timeOffset

print("begin time: \(beginTime), time offset: \(timeOffset)")
print("current time: \(CACurrentMediaTime())")

let time = CACurrentMediaTime()-beginTime
guard let immediateValue = animation.immediateValue(atTime: time) else { continue }

animatedView.layer.setValue(immediateValue, forKeyPath: animation.keyPath!)
}
}

@objc
private func handlePanGesture(_ gesture: UIPanGestureRecognizer) {
animatedView.layer.removeAllAnimations()

var point = gesture.location(in: view)

switch gesture.state {
case .began:
point = gesture.location(in: view)

let pauseTime = animatedView.layer.convertTime(CACurrentMediaTime(), from: nil)
print("pause time: \(pauseTime)")
case .possible: break
case .changed:
/*
Expand All @@ -64,12 +90,12 @@ class DecayAnimationViewController: UIViewController, UIGestureRecognizerDelegat
decayy.isRemovedOnCompletion=false
decayy.fillMode=kCAFillModeForwards
// decayy.isAdditive = true
CATransaction.setCompletionBlock({[weak self] () -> Void in
print("view's center:\(String(describing: self?.animatedView.center)), layer's position:\(String(describing: self?.animatedView.layer.position))")
self?.animatedView.layer.position = CGPoint(x: decayx.values?.last as! Double, y: decayy.values?.last as! Double)
self?.animatedView.layer.removeAllAnimations()
print("view's center:\(String(describing: self?.animatedView.center)), layer's position:\(String(describing: self?.animatedView.layer.position))")
})
// CATransaction.setCompletionBlock({[weak self] () -> Void in
// print("view's center:\(String(describing: self?.animatedView.center)), layer's position:\(String(describing: self?.animatedView.layer.position))")
// self?.animatedView.layer.position = CGPoint(x: decayx.values?.last as! Double, y: decayy.values?.last as! Double)
// self?.animatedView.layer.removeAllAnimations()
// print("view's center:\(String(describing: self?.animatedView.center)), layer's position:\(String(describing: self?.animatedView.layer.position))")
// })
CATransaction.begin()
CATransaction.setDisableActions(false)
animatedView.layer.add(decayx, forKey: "position.x")
Expand Down

0 comments on commit 2bb262f

Please sign in to comment.