Commit a9f73344 by Daniel Dahan

added depth animation to Motion

parent 65c3210c
...@@ -243,9 +243,6 @@ extension UIView { ...@@ -243,9 +243,6 @@ extension UIView {
open func transitionSnapshot(afterUpdates: Bool, shouldHide: Bool = true) -> UIView { open func transitionSnapshot(afterUpdates: Bool, shouldHide: Bool = true) -> UIView {
isHidden = false isHidden = false
// Material specific.
(self as? PulseableLayer)?.pulseLayer?.isHidden = true
let oldCornerRadius = layer.cornerRadius let oldCornerRadius = layer.cornerRadius
layer.cornerRadius = 0 layer.cornerRadius = 0
...@@ -291,9 +288,6 @@ extension UIView { ...@@ -291,9 +288,6 @@ extension UIView {
v.motionTransform = motionTransform v.motionTransform = motionTransform
v.backgroundColor = backgroundColor v.backgroundColor = backgroundColor
// Material specific.
(self as? PulseableLayer)?.pulseLayer?.isHidden = false
isHidden = shouldHide isHidden = shouldHide
return v return v
...@@ -306,15 +300,10 @@ open class MotionPresentationController: UIPresentationController { ...@@ -306,15 +300,10 @@ open class MotionPresentationController: UIPresentationController {
return return
} }
presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in })
print("Animating")
})
print("presentationTransitionWillBegin")
} }
open override func presentationTransitionDidEnd(_ completed: Bool) { open override func presentationTransitionDidEnd(_ completed: Bool) {
print("presentationTransitionDidEnd")
} }
open override func dismissalTransitionWillBegin() { open override func dismissalTransitionWillBegin() {
...@@ -322,15 +311,10 @@ open class MotionPresentationController: UIPresentationController { ...@@ -322,15 +311,10 @@ open class MotionPresentationController: UIPresentationController {
return return
} }
presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in })
print("Animating")
})
print("dismissalTransitionWillBegin")
} }
open override func dismissalTransitionDidEnd(_ completed: Bool) { open override func dismissalTransitionDidEnd(_ completed: Bool) {
print("dismissalTransitionDidEnd")
} }
open override var frameOfPresentedViewInContainerView: CGRect { open override var frameOfPresentedViewInContainerView: CGRect {
...@@ -631,6 +615,28 @@ extension Motion { ...@@ -631,6 +615,28 @@ extension Motion {
snapshotAnimations.append(Motion.transform(transform: to.motionTransform)) snapshotAnimations.append(Motion.transform(transform: to.motionTransform))
snapshotAnimations.append(Motion.background(color: to.backgroundColor ?? .clear)) snapshotAnimations.append(Motion.background(color: to.backgroundColor ?? .clear))
if let v = to.shadowPath {
snapshotAnimations.append(Motion.shadow(path: v))
}
if let path = to.shadowPath {
let shadowPath = Motion.shadow(path: path)
shadowPath.fromValue = fromView.shadowPath
snapshotAnimations.append(shadowPath)
}
let shadowOffset = Motion.shadow(offset: to.shadowOffset)
shadowOffset.fromValue = fromView.shadowOffset
snapshotAnimations.append(shadowOffset)
let shadowOpacity = Motion.shadow(opacity: to.shadowOpacity)
shadowOpacity.fromValue = fromView.shadowOpacity
snapshotAnimations.append(shadowOpacity)
let shadowRadius = Motion.shadow(radius: to.shadowRadius)
shadowRadius.fromValue = fromView.shadowRadius
snapshotAnimations.append(shadowRadius)
snapshotChildAnimations.append(cornerRadiusAnimation) snapshotChildAnimations.append(cornerRadiusAnimation)
snapshotChildAnimations.append(sizeAnimation) snapshotChildAnimations.append(sizeAnimation)
snapshotChildAnimations.append(Motion.position(x: to.bounds.width / 2, y: to.bounds.height / 2)) snapshotChildAnimations.append(Motion.position(x: to.bounds.width / 2, y: to.bounds.height / 2))
......
...@@ -48,12 +48,15 @@ public enum MotionAnimationKeyPath: String { ...@@ -48,12 +48,15 @@ public enum MotionAnimationKeyPath: String {
case translationY = "transform.translation.y" case translationY = "transform.translation.y"
case translationZ = "transform.translation.z" case translationZ = "transform.translation.z"
case position case position
case shadowPath
case opacity case opacity
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" case size = "bounds.size"
case shadowPath
case shadowOffset
case shadowOpacity
case shadowRadius
} }
public enum MotionAnimation { public enum MotionAnimation {
...@@ -85,12 +88,16 @@ public enum MotionAnimation { ...@@ -85,12 +88,16 @@ public enum MotionAnimation {
case y(CGFloat) case y(CGFloat)
case point(x: CGFloat, y: CGFloat) case point(x: CGFloat, y: CGFloat)
case position(x: CGFloat, y: CGFloat) case position(x: CGFloat, y: CGFloat)
case shadow(path: CGPath)
case fade(Double) case fade(Double)
case zPosition(Int) case zPosition(Int)
case width(CGFloat) case width(CGFloat)
case height(CGFloat) case height(CGFloat)
case size(width: CGFloat, height: CGFloat) case size(width: CGFloat, height: CGFloat)
case shadowPath(CGPath)
case shadowOffset(CGSize)
case shadowOpacity(Float)
case shadowRadius(CGFloat)
case depth(shadowOffset: CGSize, shadowOpacity: Float, shadowRadius: CGFloat)
} }
@available(iOS 10, *) @available(iOS 10, *)
...@@ -299,8 +306,6 @@ extension CALayer { ...@@ -299,8 +306,6 @@ extension CALayer {
a.append(position) a.append(position)
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):
a.append(Motion.shadow(path: path))
case let .fade(opacity): case let .fade(opacity):
let fade = Motion.fade(opacity: opacity) let fade = Motion.fade(opacity: opacity)
fade.fromValue = s.value(forKey: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1) fade.fromValue = s.value(forKey: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1)
...@@ -311,6 +316,40 @@ extension CALayer { ...@@ -311,6 +316,40 @@ extension CALayer {
a.append(zPosition) a.append(zPosition)
case .width(_), .height(_), .size(_, _): case .width(_), .height(_), .size(_, _):
a.append(Motion.size(CGSize(width: w, height: h))) a.append(Motion.size(CGSize(width: w, height: h)))
case let .shadowPath(path):
let shadowPath = Motion.shadow(path: path)
shadowPath.fromValue = s.shadowPath
a.append(shadowPath)
case let .shadowOffset(offset):
let shadowOffset = Motion.shadow(offset: offset)
shadowOffset.fromValue = s.shadowOffset
a.append(shadowOffset)
case let .shadowOpacity(opacity):
let shadowOpacity = Motion.shadow(opacity: opacity)
shadowOpacity.fromValue = s.shadowOpacity
a.append(shadowOpacity)
case let .shadowRadius(radius):
let shadowRadius = Motion.shadow(radius: radius)
shadowRadius.fromValue = s.shadowRadius
a.append(shadowRadius)
case let .depth(offset, opacity, radius):
if let path = s.shadowPath {
let shadowPath = Motion.shadow(path: path)
shadowPath.fromValue = s.shadowPath
a.append(shadowPath)
}
let shadowOffset = Motion.shadow(offset: offset)
shadowOffset.fromValue = s.shadowOffset
a.append(shadowOffset)
let shadowOpacity = Motion.shadow(opacity: opacity)
shadowOpacity.fromValue = s.shadowOpacity
a.append(shadowOpacity)
let shadowRadius = Motion.shadow(radius: radius)
shadowRadius.fromValue = s.shadowRadius
a.append(shadowRadius)
default:break default:break
} }
} }
...@@ -660,17 +699,6 @@ extension Motion { ...@@ -660,17 +699,6 @@ extension Motion {
} }
/** /**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public static func shadow(path: CGPath) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowPath)
animation.toValue = path
return animation
}
/**
Creates a CABasicAnimation for the opacity key path. Creates a CABasicAnimation for the opacity key path.
- Parameter opacity: A Double. - Parameter opacity: A Double.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
...@@ -724,4 +752,48 @@ extension Motion { ...@@ -724,4 +752,48 @@ extension Motion {
animation.toValue = NSValue(cgSize: size) animation.toValue = NSValue(cgSize: size)
return animation return animation
} }
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public static func shadow(path: CGPath) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowPath)
animation.toValue = path
return animation
}
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: CGSize.
- Returns: A CABasicAnimation.
*/
public static func shadow(offset: CGSize) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowOffset)
animation.toValue = NSValue(cgSize: offset)
return animation
}
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: Float.
- Returns: A CABasicAnimation.
*/
public static func shadow(opacity: Float) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowOpacity)
animation.toValue = NSNumber(floatLiteral: Double(opacity))
return animation
}
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: CGFloat.
- Returns: A CABasicAnimation.
*/
public static func shadow(radius: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .shadowRadius)
animation.toValue = NSNumber(floatLiteral: Double(radius))
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