Commit 3d538a63 by Daniel Dahan

development: updated transform behaviour when setting up MotionTransition

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