Commit 1e63fdbd by Daniel Dahan

development: added transitionView to MotionTransition animations

parent e46c5a84
...@@ -32,6 +32,39 @@ import UIKit ...@@ -32,6 +32,39 @@ import UIKit
/// Grid extension for UIView. /// Grid extension for UIView.
extension UIView { extension UIView {
/// A property that accesses the backing layer's masksToBounds.
@IBInspectable
open var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's opacity.
@IBInspectable
open var opacity: Float {
get {
return layer.opacity
}
set(value) {
layer.opacity = value
}
}
/// A property that accesses the backing layer's anchorPoint.
@IBInspectable
open var anchorPoint: CGPoint {
get {
return layer.anchorPoint
}
set(value) {
layer.anchorPoint = value
}
}
/// A property that accesses the frame.origin.x property. /// A property that accesses the frame.origin.x property.
@IBInspectable @IBInspectable
open var x: CGFloat { open var x: CGFloat {
......
...@@ -52,6 +52,7 @@ public enum MotionAnimationKeyPath: String { ...@@ -52,6 +52,7 @@ public enum MotionAnimationKeyPath: String {
case zPosition case zPosition
case width = "bounds.size.width" case width = "bounds.size.width"
case height = "bounds.size.height" case height = "bounds.size.height"
case size = "bounds.size"
} }
public enum MotionAnimation { public enum MotionAnimation {
...@@ -87,6 +88,7 @@ public enum MotionAnimation { ...@@ -87,6 +88,7 @@ public enum MotionAnimation {
case zPosition(Int) case zPosition(Int)
case width(CGFloat) case width(CGFloat)
case height(CGFloat) case height(CGFloat)
case size(CGSize)
} }
extension CALayer { extension CALayer {
...@@ -190,6 +192,22 @@ extension CALayer { ...@@ -190,6 +192,22 @@ extension CALayer {
var tf = timingFunction var tf = timingFunction
var d = duration var d = duration
var px: CGFloat = s.position.x
var py: CGFloat = s.position.y
for v in animations {
switch v {
case let .x(x):
px = x + w / 2
case let .y(y):
py = y + h / 2
case let .point(x, y):
px = x + w / 2
py = y + h / 2
default:break
}
}
for v in animations { for v in animations {
switch v { switch v {
case let .timingFunction(timingFunction): case let .timingFunction(timingFunction):
...@@ -239,12 +257,9 @@ extension CALayer { ...@@ -239,12 +257,9 @@ extension CALayer {
a.append(Motion.translateY(to: to)) a.append(Motion.translateY(to: to))
case let .translateZ(to): case let .translateZ(to):
a.append(Motion.translateZ(to: to)) a.append(Motion.translateZ(to: to))
case let .x(x): case let .x(_), .y(_), .point(_, _):
a.append(Motion.position(to: CGPoint(x: x + w / 2, y: s.position.y))) let position = Motion.position(to: CGPoint(x: px, y: py))
case let .y(y): a.append(position)
a.append(Motion.position(to: CGPoint(x: s.position.x, y: y + h / 2)))
case let .point(x, y):
a.append(Motion.position(to: CGPoint(x: x + w / 2, y: y + h / 2)))
case let .position(x, y): case let .position(x, y):
a.append(Motion.position(to: CGPoint(x: x, y: y))) a.append(Motion.position(to: CGPoint(x: x, y: y)))
case let .shadow(path): case let .shadow(path):
...@@ -261,6 +276,8 @@ extension CALayer { ...@@ -261,6 +276,8 @@ extension CALayer {
a.append(Motion.width(w)) a.append(Motion.width(w))
case let .height(h): case let .height(h):
a.append(Motion.height(h)) a.append(Motion.height(h))
case let .size(size):
a.append(Motion.size(size))
default:break default:break
} }
} }
...@@ -523,6 +540,18 @@ extension Motion { ...@@ -523,6 +540,18 @@ extension Motion {
/** /**
Creates a CABasicAnimation for the position key path. Creates a CABasicAnimation for the position key path.
- Parameter x: A CGFloat.
- Parameter y: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func position(x: CGFloat, y: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .position)
animation.toValue = NSValue(cgPoint: CGPoint(x: x, y: y))
return animation
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter to point: A CGPoint. - Parameter to point: A CGPoint.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
...@@ -586,4 +615,15 @@ extension Motion { ...@@ -586,4 +615,15 @@ extension Motion {
animation.toValue = NSNumber(floatLiteral: Double(height)) animation.toValue = NSNumber(floatLiteral: Double(height))
return animation return animation
} }
/**
Creates a CABasicaAnimation for the height key path.
- Parameter size: A CGSize.
- Returns: A CABasicAnimation.
*/
public static func size(_ size: CGSize) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .size)
animation.toValue = NSValue(cgSize: size)
return animation
}
} }
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