Commit 398021c6 by Daniel Dahan

updated Motion+Array and Motion+CALayer

parent 1127ed5a
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
import UIKit import UIKit
internal extension Array { internal extension Array {
/**
Retrieves the element at the given index if it exists.
- Parameter _ index: An Int.
- Returns: An optional Element value.
*/
func get(_ index: Int) -> Element? { func get(_ index: Int) -> Element? {
if index < count { if index < count {
return self[index] return self[index]
...@@ -38,28 +43,63 @@ internal extension Array { ...@@ -38,28 +43,63 @@ internal extension Array {
} }
internal extension Array where Element: ExprNode { internal extension Array where Element: ExprNode {
/**
Retrieves the element at the given index if it exists
as a CGFloat.
- Parameter _ index: An Int.
- Returns: An optional CGFloat value.
*/
func getCGFloat(_ index: Int) -> CGFloat? { func getCGFloat(_ index: Int) -> CGFloat? {
if let s = get(index) as? NumberNode { guard let s = get(index) as? NumberNode else {
return nil
}
return CGFloat(s.value) return CGFloat(s.value)
} }
/**
Retrieves the element at the given index if it exists
as a Double.
- Parameter _ index: An Int.
- Returns: An optional Double value.
*/
func getDouble(_ index: Int) -> Double? {
guard let s = get(index) as? NumberNode else {
return nil return nil
} }
func getDouble(_ index: Int) -> Double? {
if let s = get(index) as? NumberNode {
return Double(s.value) return Double(s.value)
} }
/**
Retrieves the element at the given index if it exists
as a Float.
- Parameter _ index: An Int.
- Returns: An optional Float value.
*/
func getFloat(_ index: Int) -> Float? {
guard let s = get(index) as? NumberNode else {
return nil return nil
} }
func getFloat(_ index: Int) -> Float? {
if let s = get(index) as? NumberNode {
return s.value return s.value
} }
return nil
} /**
Retrieves the element at the given index if it exists
as a Bool.
- Parameter _ index: An Int.
- Returns: An optional Bool value.
*/
func getBool(_ index: Int) -> Bool? { func getBool(_ index: Int) -> Bool? {
if let s = get(index) as? VariableNode, let f = Bool(s.name) { guard let s = get(index) as? VariableNode else {
return f return nil
} }
guard let f = Bool(s.name) else {
return nil return nil
} }
return f
}
} }
...@@ -28,19 +28,21 @@ ...@@ -28,19 +28,21 @@
import UIKit import UIKit
@available(iOS 10, *)
extension CALayer: CAAnimationDelegate {}
internal extension CALayer { internal extension CALayer {
// return all animations running by this layer. /// Retrieves all currently running animations for the layer.
// the returned value is mutable
var animations: [(String, CAAnimation)] { var animations: [(String, CAAnimation)] {
if let keys = animationKeys() { guard let keys = animationKeys() else {
return keys.map { return ($0, self.animation(forKey: $0)!.copy() as! CAAnimation) }
}
return [] return []
} }
}
@available(iOS 10, *) return keys.map {
extension CALayer: CAAnimationDelegate {} return ($0, self.animation(forKey: $0)!.copy() as! CAAnimation)
}
}
}
extension CALayer { extension CALayer {
/** /**
...@@ -77,6 +79,10 @@ extension CALayer { ...@@ -77,6 +79,10 @@ extension CALayer {
} }
} }
/**
Executed when an animation has started.
- Parameter _ anim: A CAAnimation.
*/
public func animationDidStart(_ anim: CAAnimation) {} public func animationDidStart(_ anim: CAAnimation) {}
/** /**
......
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