Commit 3d538a63 by Daniel Dahan

development: updated transform behaviour when setting up MotionTransition

parent c7200fdf
...@@ -61,20 +61,20 @@ public enum MotionAnimation { ...@@ -61,20 +61,20 @@ public enum MotionAnimation {
case duration(TimeInterval) case duration(TimeInterval)
case custom(CABasicAnimation) case custom(CABasicAnimation)
case backgroundColor(UIColor) case backgroundColor(UIColor)
case corners(CGFloat) case cornerRadius(CGFloat)
case transform(CATransform3D) case transform(CATransform3D)
case rotate(Double) case rotationAngle(CGFloat)
case rotateX(Double) case rotationAngleX(CGFloat)
case rotateY(Double) case rotationAngleY(CGFloat)
case rotateZ(Double) case rotationAngleZ(CGFloat)
case spin(Double) case spin(CGFloat)
case spinX(Double) case spinX(CGFloat)
case spinY(Double) case spinY(CGFloat)
case spinZ(Double) case spinZ(CGFloat)
case scale(Double) case scale(CGFloat)
case scaleX(Double) case scaleX(CGFloat)
case scaleY(Double) case scaleY(CGFloat)
case scaleZ(Double) case scaleZ(CGFloat)
case translate(x: CGFloat, y: CGFloat) case translate(x: CGFloat, y: CGFloat)
case translateX(CGFloat) case translateX(CGFloat)
case translateY(CGFloat) case translateY(CGFloat)
...@@ -243,19 +243,19 @@ extension CALayer { ...@@ -243,19 +243,19 @@ extension CALayer {
a.append(animation) a.append(animation)
case let .backgroundColor(color): case let .backgroundColor(color):
a.append(Motion.background(color: color)) a.append(Motion.background(color: color))
case let .corners(radius): case let .cornerRadius(radius):
a.append(Motion.corner(radius: radius)) a.append(Motion.corner(radius: radius))
case let .transform(transform): case let .transform(transform):
a.append(Motion.transform(transform: transform)) a.append(Motion.transform(transform: transform))
case let .rotate(angle): case let .rotationAngle(angle):
let rotate = Motion.rotate(angle: angle) let rotate = Motion.rotation(angle: angle)
a.append(rotate) a.append(rotate)
case let .rotateX(angle): case let .rotationAngleX(angle):
a.append(Motion.rotateX(angle: angle)) a.append(Motion.rotationX(angle: angle))
case let .rotateY(angle): case let .rotationAngleY(angle):
a.append(Motion.rotateY(angle: angle)) a.append(Motion.rotationY(angle: angle))
case let .rotateZ(angle): case let .rotationAngleZ(angle):
a.append(Motion.rotateZ(angle: angle)) a.append(Motion.rotationZ(angle: angle))
case let .spin(rotations): case let .spin(rotations):
a.append(Motion.spin(rotations: rotations)) a.append(Motion.spin(rotations: rotations))
case let .spinX(rotations): case let .spinX(rotations):
...@@ -316,8 +316,13 @@ extension CALayer: CAAnimationDelegate {} ...@@ -316,8 +316,13 @@ extension CALayer: CAAnimationDelegate {}
extension UIView { extension UIView {
/// Computes the rotation of the view. /// Computes the rotation of the view.
open var motionRotationAngle: Double { open var motionRotationAngle: CGFloat {
return Double(atan2f(Float(transform.b), Float(transform.a))) * 180 / M_PI get {
return CGFloat(atan2f(Float(transform.b), Float(transform.a))) * 180 / CGFloat(M_PI)
}
set(value) {
transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) * value / 180)
}
} }
/// Computes the scale X axis value of the view. /// Computes the scale X axis value of the view.
...@@ -413,133 +418,133 @@ extension Motion { ...@@ -413,133 +418,133 @@ extension Motion {
/** /**
Creates a CABasicAnimation for the transform.rotation key path. Creates a CABasicAnimation for the transform.rotation key path.
- Parameter angle: An optional Double. - Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func rotate(angle: Double) -> CABasicAnimation { public static func rotation(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotation) let animation = CABasicAnimation(keyPath: .rotation)
animation.toValue = NSNumber(floatLiteral: M_PI * angle / 180) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.x key path. Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter angle: An optional Double. - Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func rotateX(angle: Double) -> CABasicAnimation { public static func rotationX(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationX) let animation = CABasicAnimation(keyPath: .rotationX)
animation.toValue = NSNumber(floatLiteral: M_PI * angle / 180) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.y key path. Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter angle: An optional Double. - Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func rotateY(angle: Double) -> CABasicAnimation { public static func rotationY(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationY) let animation = CABasicAnimation(keyPath: .rotationY)
animation.toValue = NSNumber(floatLiteral: M_PI * angle / 180) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.z key path. Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter angle: An optional Double. - Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func rotateZ(angle: Double) -> CABasicAnimation { public static func rotationZ(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationZ) let animation = CABasicAnimation(keyPath: .rotationZ)
animation.toValue = NSNumber(floatLiteral: M_PI * angle / 180) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation key path. Creates a CABasicAnimation for the transform.rotation key path.
- Parameter rotations: An optional Double. - Parameter rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spin(rotations: Double) -> CABasicAnimation { public static func spin(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotation) let animation = CABasicAnimation(keyPath: .rotation)
animation.toValue = NSNumber(floatLiteral: M_PI * 2 * rotations) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.x key path. Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter rotations: An optional Double. - Parameter rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinX(rotations: Double) -> CABasicAnimation { public static func spinX(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationX) let animation = CABasicAnimation(keyPath: .rotationX)
animation.toValue = NSNumber(floatLiteral: M_PI * 2 * rotations) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.y key path. Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter rotations: An optional Double. - Parameter rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinY(rotations: Double) -> CABasicAnimation { public static func spinY(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationY) let animation = CABasicAnimation(keyPath: .rotationY)
animation.toValue = NSNumber(floatLiteral: M_PI * 2 * rotations) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.rotation.z key path. Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter rotations: An optional Double. - Parameter rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinZ(rotations: Double) -> CABasicAnimation { public static func spinZ(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationZ) let animation = CABasicAnimation(keyPath: .rotationZ)
animation.toValue = NSNumber(floatLiteral: M_PI * 2 * rotations) animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.scale key path. Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A Double. - Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func scale(to scale: Double) -> CABasicAnimation { public static func scale(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scale) let animation = CABasicAnimation(keyPath: .scale)
animation.toValue = NSNumber(floatLiteral: scale) animation.toValue = NSNumber(floatLiteral: Double(scale))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.scale.x key path. Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A Double. - Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func scaleX(to scale: Double) -> CABasicAnimation { public static func scaleX(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleX) let animation = CABasicAnimation(keyPath: .scaleX)
animation.toValue = NSNumber(floatLiteral: scale) animation.toValue = NSNumber(floatLiteral: Double(scale))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.scale.y key path. Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A Double. - Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func scaleY(to scale: Double) -> CABasicAnimation { public static func scaleY(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleY) let animation = CABasicAnimation(keyPath: .scaleY)
animation.toValue = NSNumber(floatLiteral: scale) animation.toValue = NSNumber(floatLiteral: Double(scale))
return animation return animation
} }
/** /**
Creates a CABasicAnimation for the transform.scale.z key path. Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A Double. - Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func scaleZ(to scale: Double) -> CABasicAnimation { public static func scaleZ(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleZ) let animation = CABasicAnimation(keyPath: .scaleZ)
animation.toValue = NSNumber(floatLiteral: scale) animation.toValue = NSNumber(floatLiteral: Double(scale))
return animation return animation
} }
......
...@@ -84,17 +84,17 @@ extension UIViewController { ...@@ -84,17 +84,17 @@ extension UIViewController {
} }
} }
//extension UIViewController { extension UIViewController {
// open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
// return isMotionTransitionEnabled ? MotionTransition(isPresenting: operation == .push) : nil return isMotionTransitionEnabled ? MotionTransition(isPresenting: operation == .push) : nil
// } }
//} }
//
//extension UIViewController { extension UIViewController {
// open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
// return isMotionTransitionEnabled ? MotionTransition() : nil return isMotionTransitionEnabled ? MotionTransition() : nil
// } }
//} }
extension UIView { extension UIView {
/// The global position of a view. /// The global position of a view.
...@@ -143,11 +143,13 @@ extension UIView { ...@@ -143,11 +143,13 @@ extension UIView {
let oldBackgroundColor = backgroundColor let oldBackgroundColor = backgroundColor
backgroundColor = .clear backgroundColor = .clear
let oldTransform = transform
transform = .identity
let v = snapshotView(afterScreenUpdates: afterUpdates)! let v = snapshotView(afterScreenUpdates: afterUpdates)!
cornerRadius = oldCornerRadius cornerRadius = oldCornerRadius
backgroundColor = oldBackgroundColor backgroundColor = oldBackgroundColor
v.backgroundColor = oldBackgroundColor transform = oldTransform
let contentView = v.subviews.first! let contentView = v.subviews.first!
contentView.cornerRadius = cornerRadius contentView.cornerRadius = cornerRadius
...@@ -169,7 +171,10 @@ extension UIView { ...@@ -169,7 +171,10 @@ extension UIView {
v.shadowColor = shadowColor v.shadowColor = shadowColor
v.shadowOffset = shadowOffset v.shadowOffset = shadowOffset
v.contentMode = contentMode v.contentMode = contentMode
v.layer.transform = layer.transform v.transform = transform
v.backgroundColor = backgroundColor
print(motionRotationAngle)
isHidden = true isHidden = true
(self as? Pulseable)?.pulse.pulseLayer?.isHidden = false (self as? Pulseable)?.pulse.pulseLayer?.isHidden = false
...@@ -372,21 +377,18 @@ extension MotionTransition { ...@@ -372,21 +377,18 @@ extension MotionTransition {
var snapshotAnimations = [CABasicAnimation]() var snapshotAnimations = [CABasicAnimation]()
var snapshotChildAnimations = [CABasicAnimation]() var snapshotChildAnimations = [CABasicAnimation]()
snapshotAnimations.append(Motion.position(to: tv.motionPosition))
let sizeAnimation = Motion.size(tv.bounds.size) let sizeAnimation = Motion.size(tv.bounds.size)
snapshotAnimations.append(sizeAnimation) let cornerRadiusAnimation = Motion.corner(radius: tv.cornerRadius)
snapshotChildAnimations.append(sizeAnimation)
snapshotChildAnimations.append(Motion.position(x: tv.bounds.width / 2, y: tv.bounds.height / 2))
snapshotAnimations.append(Motion.rotate(angle: tv.motionRotationAngle))
snapshotAnimations.append(sizeAnimation)
snapshotAnimations.append(cornerRadiusAnimation)
snapshotAnimations.append(Motion.position(to: tv.motionPosition))
snapshotAnimations.append(Motion.rotation(angle: tv.motionRotationAngle))
snapshotAnimations.append(Motion.background(color: tv.backgroundColor ?? .clear)) snapshotAnimations.append(Motion.background(color: tv.backgroundColor ?? .clear))
let cornerRadiusAnimation = Motion.corner(radius: tv.cornerRadius)
snapshotAnimations.append(cornerRadiusAnimation)
snapshotChildAnimations.append(cornerRadiusAnimation) snapshotChildAnimations.append(cornerRadiusAnimation)
snapshotChildAnimations.append(sizeAnimation)
snapshotChildAnimations.append(Motion.position(x: tv.bounds.width / 2, y: tv.bounds.height / 2))
let snapshot = fv.motionTransitionSnapshot(afterUpdates: true) let snapshot = fv.motionTransitionSnapshot(afterUpdates: true)
transitionView.insertSubview(snapshot, belowSubview: transitionSnapshot) transitionView.insertSubview(snapshot, belowSubview: transitionSnapshot)
......
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