Commit ca611b57 by Daniel Dahan

development: shortened MotionAnimation enum type parameters

parent 02c71dde
...@@ -2,7 +2,7 @@ Pod::Spec.new do |s| ...@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '2.4.9' s.version = '2.4.9'
s.license = 'BSD-3-Clause' s.license = 'BSD-3-Clause'
s.summary = 'Material is an animation and graphics framework that brings Material Design to iOS with Swift 3.' s.summary = 'An animation and graphics framework for Material Design in Swift.'
s.homepage = 'http://materialswift.com' s.homepage = 'http://materialswift.com'
s.social_media_url = 'https://www.facebook.com/cosmicmindio' s.social_media_url = 'https://www.facebook.com/cosmicmindio'
s.authors = { 'CosmicMind, Inc.' => 'support@cosmicmind.com' } s.authors = { 'CosmicMind, Inc.' => 'support@cosmicmind.com' }
......
...@@ -52,28 +52,29 @@ public enum MotionAnimationKeyPath: String { ...@@ -52,28 +52,29 @@ public enum MotionAnimationKeyPath: String {
} }
public enum MotionAnimation { public enum MotionAnimation {
case background(color: UIColor) case custom(CABasicAnimation)
case corner(radius: CGFloat) case backgroundColor(UIColor)
case transform(transform: CATransform3D) case corners(CGFloat)
case rotate(angle: CGFloat) case transform(CATransform3D)
case rotateX(angle: CGFloat) case rotate(CGFloat)
case rotateY(angle: CGFloat) case rotateX(CGFloat)
case rotateZ(angle: CGFloat) case rotateY(CGFloat)
case spin(rotations: CGFloat) case rotateZ(CGFloat)
case spinX(rotations: CGFloat) case spin(CGFloat)
case spinY(rotations: CGFloat) case spinX(CGFloat)
case spinZ(rotations: CGFloat) case spinY(CGFloat)
case scale(to: CGFloat) case spinZ(CGFloat)
case scaleX(to: CGFloat) case scale(CGFloat)
case scaleY(to: CGFloat) case scaleX(CGFloat)
case scaleZ(to: CGFloat) case scaleY(CGFloat)
case move(to: CGPoint) case scaleZ(CGFloat)
case moveX(to: CGFloat) case translate(x: CGFloat, y: CGFloat)
case moveY(to: CGFloat) case translateX(CGFloat)
case moveZ(to: CGFloat) case translateY(CGFloat)
case position(to: CGPoint) case translateZ(CGFloat)
case position(x: CGFloat, y: CGFloat)
case shadow(path: CGPath) case shadow(path: CGPath)
case fade(opacity: CGFloat) case fade(CGFloat)
} }
extension CALayer { extension CALayer {
...@@ -167,9 +168,11 @@ extension CALayer { ...@@ -167,9 +168,11 @@ extension CALayer {
for v in animations { for v in animations {
switch v { switch v {
case let .background(color): case let .custom(animation):
a.append(animation)
case let .backgroundColor(color):
a.append(Motion.background(color: color)) a.append(Motion.background(color: color))
case let .corner(radius): case let .corners(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))
...@@ -197,16 +200,16 @@ extension CALayer { ...@@ -197,16 +200,16 @@ extension CALayer {
a.append(Motion.scaleY(to: to)) a.append(Motion.scaleY(to: to))
case let .scaleZ(to): case let .scaleZ(to):
a.append(Motion.scaleZ(to: to)) a.append(Motion.scaleZ(to: to))
case let .move(to): case let .translate(x, y):
a.append(Motion.move(to: to)) a.append(Motion.translate(to: CGPoint(x: x, y: y)))
case let .moveX(to): case let .translateX(to):
a.append(Motion.moveX(to: to)) a.append(Motion.translateX(to: to))
case let .moveY(to): case let .translateY(to):
a.append(Motion.moveY(to: to)) a.append(Motion.translateY(to: to))
case let .moveZ(to): case let .translateZ(to):
a.append(Motion.moveZ(to: to)) a.append(Motion.translateZ(to: to))
case let .position(to): case let .position(x, y):
a.append(Motion.position(to: to)) a.append(Motion.position(to: CGPoint(x: x, y: y)))
case let .shadow(path): case let .shadow(path):
a.append(Motion.shadow(path: path)) a.append(Motion.shadow(path: path))
case let .fade(opacity): case let .fade(opacity):
...@@ -539,7 +542,7 @@ extension Motion { ...@@ -539,7 +542,7 @@ extension Motion {
- Parameter point: A CGPoint. - Parameter point: A CGPoint.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func move(to point: CGPoint, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translate(to point: CGPoint, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translation) let animation = CABasicAnimation(keyPath: .translation)
animation.toValue = NSValue(cgPoint: point) animation.toValue = NSValue(cgPoint: point)
return animation return animation
...@@ -550,7 +553,7 @@ extension Motion { ...@@ -550,7 +553,7 @@ extension Motion {
- Parameter to translation: A CGFloat. - Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func moveX(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateX(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationX) let animation = CABasicAnimation(keyPath: .translationX)
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
return animation return animation
...@@ -561,7 +564,7 @@ extension Motion { ...@@ -561,7 +564,7 @@ extension Motion {
- Parameter to translation: A CGFloat. - Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func moveY(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateY(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationY) let animation = CABasicAnimation(keyPath: .translationY)
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
return animation return animation
...@@ -572,7 +575,7 @@ extension Motion { ...@@ -572,7 +575,7 @@ extension Motion {
- Parameter to translation: A CGFloat. - Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func moveZ(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation { public static func translateZ(to translation: CGFloat, duration: CFTimeInterval? = nil) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationZ) let animation = CABasicAnimation(keyPath: .translationZ)
animation.toValue = translation as NSNumber animation.toValue = translation as NSNumber
return animation return animation
......
...@@ -36,9 +36,21 @@ public enum MotionTransition: Int { ...@@ -36,9 +36,21 @@ public enum MotionTransition: Int {
case fade case fade
} }
extension UIViewController: UIViewControllerTransitioningDelegate { open class MotionTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return FadeMotionTransition() return nil
}
open func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil
}
open func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return nil
}
open func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return nil
} }
} }
...@@ -62,13 +74,52 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning ...@@ -62,13 +74,52 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
toView.alpha = 1 toView.alpha = 1
fromView.alpha = 0 fromView.alpha = 0
}) { _ in }) { _ in
transitionContext.completeTransition(true) let success = !transitionContext.transitionWasCancelled
transitionContext.completeTransition(success)
}
}
open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.35
}
open func animationEnded(_ transitionCompleted: Bool) {
print("FadeMotionTransition ANIMATION ENDED")
}
}
open class SlideMotionTransition: NSObject, UIViewControllerAnimatedTransitioning {
open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else {
return
}
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else {
return
}
toView.y = fromView.height
transitionContext.containerView.addSubview(fromView)
transitionContext.containerView.addSubview(toView)
UIView.animate(withDuration: transitionDuration(using: transitionContext),
animations: { _ in
toView.frame = fromView.frame
// fromView.alpha = 0
}) { _ in
let success = !transitionContext.transitionWasCancelled
transitionContext.completeTransition(success)
} }
} }
open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.35 return 0.35
} }
open func animationEnded(_ transitionCompleted: Bool) {
print("SlideMotionTransition ANIMATION ENDED")
}
} }
......
...@@ -136,7 +136,7 @@ open class NavigationController: UINavigationController { ...@@ -136,7 +136,7 @@ open class NavigationController: UINavigationController {
extension NavigationController: UINavigationControllerDelegate { extension NavigationController: UINavigationControllerDelegate {
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 FadeMotionTransition() return SlideMotionTransition()
} }
} }
......
...@@ -146,13 +146,13 @@ extension PulseMotion { ...@@ -146,13 +146,13 @@ extension PulseMotion {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap: case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.motion(duration: duration, animations: .background(color: color.withAlphaComponent(opacity / 2))) bLayer.motion(duration: duration, animations: .backgroundColor(color.withAlphaComponent(opacity / 2)))
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.motion(duration: duration, animations: .scale(to: 1)) pLayer.motion(duration: duration, animations: .scale(1))
default:break default:break
} }
...@@ -182,13 +182,13 @@ extension PulseMotion { ...@@ -182,13 +182,13 @@ extension PulseMotion {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap: case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.motion(duration: duration, animations: .background(color: color.withAlphaComponent(0))) bLayer.motion(duration: duration, animations: .backgroundColor(color.withAlphaComponent(0)))
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.motion(duration: duration, animations: .scale(to: .center == animation ? 1 : 1.325), .background(color: color.withAlphaComponent(0))) pLayer.motion(duration: duration, animations: .scale(.center == animation ? 1 : 1.325), .backgroundColor(color.withAlphaComponent(0)))
default:break default:break
} }
......
...@@ -143,6 +143,7 @@ open class TabBar: Bar { ...@@ -143,6 +143,7 @@ open class TabBar: Bar {
prepareLineAnimationHandler(button: b) prepareLineAnimationHandler(button: b)
} }
} }
contentView.grid.axis.columns = buttons.count contentView.grid.axis.columns = buttons.count
contentView.grid.reload() contentView.grid.reload()
......
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