Commit 1ef94e71 by Daniel Dahan

development: updated Animation to Motion

parent 486cab29
......@@ -184,13 +184,13 @@ open class Button: UIButton {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Motion.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
Motion.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
bringImageViewToFront()
......@@ -204,7 +204,7 @@ open class Button: UIButton {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
bringImageViewToFront()
}
......@@ -217,7 +217,7 @@ open class Button: UIButton {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -228,7 +228,7 @@ open class Button: UIButton {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
open func bringImageViewToFront() {
......
......@@ -238,13 +238,13 @@ open class CollectionReusableView: UICollectionReusableView {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Motion.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
Motion.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -256,7 +256,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -267,7 +267,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -278,7 +278,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
......@@ -245,13 +245,13 @@ open class CollectionViewCell: UICollectionViewCell {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Motion.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
Motion.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -263,7 +263,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -274,7 +274,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -285,7 +285,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
......@@ -321,7 +321,7 @@ extension CALayer {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
let a = Animation.shadowPath(to: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath)
let a = Motion.shadowPath(to: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath)
a.fromValue = shadowPath
animate(animation: a)
}
......
......@@ -57,11 +57,11 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> String {
@objc(AnimationTimingFunction)
public enum AnimationTimingFunction: Int {
case `default`
case linear
case easeIn
case easeOut
case easeInEaseOut
case `default`
}
/**
......@@ -86,7 +86,7 @@ public func AnimationTimingFunctionToValue(function: AnimationTimingFunction) ->
public typealias AnimationDelayCancelBlock = (Bool) -> Void
public struct Animation {
public struct Motion {
/**
Executes a block of code after a time delay.
- Parameter duration: An animation duration time.
......@@ -160,7 +160,7 @@ public struct Animation {
- Returns: A CAAnimationGroup.
*/
public static func animate(group animations: [CAAnimation], duration: CFTimeInterval = 0.5) -> CAAnimationGroup {
let group: CAAnimationGroup = CAAnimationGroup()
let group = CAAnimationGroup()
group.fillMode = AnimationFillModeToValue(mode: .forwards)
group.isRemovedOnCompletion = false
group.animations = animations
......@@ -183,3 +183,4 @@ public struct Animation {
}
}
}
......@@ -60,7 +60,7 @@ extension CABasicAnimation {
}
}
extension Animation {
extension Motion {
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
......
......@@ -53,7 +53,7 @@ public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String?
}
}
extension Animation {
extension Motion {
/**
Creates a CAKeyframeAnimation.
- Parameter bezierPath: A UIBezierPath.
......
......@@ -85,7 +85,7 @@ public func AnimationTransitionDirectionToValue(direction: AnimationTransitionDi
}
}
extension Animation {
extension Motion {
/**
Creates a CATransition animation.
- Parameter type: An AnimationTransition.
......
......@@ -42,7 +42,7 @@ public enum PulseAnimation: Int {
case pointWithBacking
}
internal extension Animation {
internal extension Motion {
/**
Triggers the expanding animation.
- Parameter layer: Container CALayer.
......@@ -71,7 +71,7 @@ internal extension Animation {
visualLayer.masksToBounds = !(.centerRadialBeyondBounds == pulse.animation || .radialBeyondBounds == pulse.animation)
Animation.disable(animations: { [visualLayer = visualLayer, pulse = pulse] in
Motion.disable(animations: { [visualLayer = visualLayer, pulse = pulse] in
bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRect(x: 0, y: 0, width: n, height: n)
......@@ -93,17 +93,17 @@ internal extension Animation {
switch pulse.animation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Animation.backgroundColor(color: pulse.color.withAlphaComponent(pulse.opacity / 2), duration: duration), forKey: nil)
bLayer.add(Motion.backgroundColor(color: pulse.color.withAlphaComponent(pulse.opacity / 2), duration: duration), forKey: nil)
default:break
}
switch pulse.animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Animation.scale(by: 1, duration: duration), forKey: nil)
pLayer.add(Motion.scale(by: 1, duration: duration), forKey: nil)
default:break
}
Animation.delay(time: duration) {
Motion.delay(time: duration) {
bLayer.setValue(true, forKey: "animated")
}
}
......@@ -123,7 +123,7 @@ internal extension Animation {
return
}
Animation.delay(time: animated ? 0 : 0.15) { [pulse = pulse] in
Motion.delay(time: animated ? 0 : 0.15) { [pulse = pulse] in
guard let pLayer = bLayer.sublayers?.first as? CAShapeLayer else {
return
}
......@@ -132,20 +132,20 @@ internal extension Animation {
switch pulse.animation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Animation.backgroundColor(color: pulse.color.withAlphaComponent(0), duration: duration), forKey: nil)
bLayer.add(Motion.backgroundColor(color: pulse.color.withAlphaComponent(0), duration: duration), forKey: nil)
default:break
}
switch pulse.animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Animation.animate(group: [
Animation.scale(by: .center == pulse.animation ? 1 : 1.325),
Animation.backgroundColor(color: pulse.color.withAlphaComponent(0))
pLayer.add(Motion.animate(group: [
Motion.scale(by: .center == pulse.animation ? 1 : 1.325),
Motion.backgroundColor(color: pulse.color.withAlphaComponent(0))
], duration: duration), forKey: nil)
default:break
}
Animation.delay(time: duration) {
Motion.delay(time: duration) {
pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer()
}
......
......@@ -72,13 +72,13 @@ open class PulseView: View {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Motion.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
Motion.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -90,7 +90,7 @@ open class PulseView: View {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -101,7 +101,7 @@ open class PulseView: View {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -112,6 +112,6 @@ open class PulseView: View {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
}
......@@ -108,7 +108,7 @@ open class SnackbarController: RootController {
*/
@discardableResult
open func animate(snackbar status: SnackbarStatus, delay: TimeInterval = 0, animations: ((Snackbar) -> Void)? = nil, completion: ((Snackbar) -> Void)? = nil) -> AnimationDelayCancelBlock? {
return Animation.delay(time: delay) { [weak self, status = status, animations = animations, completion = completion] in
return Motion.delay(time: delay) { [weak self, status = status, animations = animations, completion = completion] in
guard let s = self else {
return
}
......
......@@ -122,13 +122,13 @@ open class TableViewCell: UITableViewCell {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Motion.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
Motion.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -140,7 +140,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
Motion.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -151,7 +151,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -162,7 +162,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
Motion.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
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