Commit e352f7a9 by Daniel Dahan

development: refined MotionTransition additions

parent 3d538a63
/* /*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
...@@ -86,7 +86,7 @@ private class FontLoader { ...@@ -86,7 +86,7 @@ private class FontLoader {
let bundle = Bundle(for: FontLoader.self) let bundle = Bundle(for: FontLoader.self)
let identifier = bundle.bundleIdentifier let identifier = bundle.bundleIdentifier
let fontURL = true == identifier?.hasPrefix("org.cocoapods") ? bundle.url(forResource: name, withExtension: "ttf", subdirectory: "io.cosmicmind.material.fonts.bundle") : bundle.url(forResource: name, withExtension: "ttf") let fontURL = true == identifier?.hasPrefix("org.cocoapods") ? bundle.url(forResource: name, withExtension: "ttf", subdirectory: "com.cosmicmind.material.fonts.bundle") : bundle.url(forResource: name, withExtension: "ttf")
if let v = fontURL { if let v = fontURL {
let data = NSData(contentsOf: v as URL)! let data = NSData(contentsOf: v as URL)!
......
...@@ -42,7 +42,7 @@ public struct Icon { ...@@ -42,7 +42,7 @@ public struct Icon {
if nil == Icon.internalBundle { if nil == Icon.internalBundle {
Icon.internalBundle = Bundle(for: View.self) Icon.internalBundle = Bundle(for: View.self)
let url = Icon.internalBundle!.resourceURL! let url = Icon.internalBundle!.resourceURL!
let b = Bundle(url: url.appendingPathComponent("io.cosmicmind.material.icons.bundle")) let b = Bundle(url: url.appendingPathComponent("com.cosmicmind.material.icons.bundle"))
if let v = b { if let v = b {
Icon.internalBundle = v Icon.internalBundle = v
} }
......
...@@ -423,7 +423,7 @@ extension Motion { ...@@ -423,7 +423,7 @@ extension Motion {
*/ */
public static func rotation(angle: CGFloat) -> CABasicAnimation { public static func rotation(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotation) let animation = CABasicAnimation(keyPath: .rotation)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
...@@ -434,7 +434,7 @@ extension Motion { ...@@ -434,7 +434,7 @@ extension Motion {
*/ */
public static func rotationX(angle: CGFloat) -> CABasicAnimation { public static func rotationX(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationX) let animation = CABasicAnimation(keyPath: .rotationX)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
...@@ -445,7 +445,7 @@ extension Motion { ...@@ -445,7 +445,7 @@ extension Motion {
*/ */
public static func rotationY(angle: CGFloat) -> CABasicAnimation { public static func rotationY(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationY) let animation = CABasicAnimation(keyPath: .rotationY)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
...@@ -456,7 +456,7 @@ extension Motion { ...@@ -456,7 +456,7 @@ extension Motion {
*/ */
public static func rotationZ(angle: CGFloat) -> CABasicAnimation { public static func rotationZ(angle: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationZ) let animation = CABasicAnimation(keyPath: .rotationZ)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * angle / 180)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * angle / 180))
return animation return animation
} }
...@@ -467,7 +467,7 @@ extension Motion { ...@@ -467,7 +467,7 @@ extension Motion {
*/ */
public static func spin(rotations: CGFloat) -> CABasicAnimation { public static func spin(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotation) let animation = CABasicAnimation(keyPath: .rotation)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
...@@ -478,7 +478,7 @@ extension Motion { ...@@ -478,7 +478,7 @@ extension Motion {
*/ */
public static func spinX(rotations: CGFloat) -> CABasicAnimation { public static func spinX(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationX) let animation = CABasicAnimation(keyPath: .rotationX)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
...@@ -489,7 +489,7 @@ extension Motion { ...@@ -489,7 +489,7 @@ extension Motion {
*/ */
public static func spinY(rotations: CGFloat) -> CABasicAnimation { public static func spinY(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationY) let animation = CABasicAnimation(keyPath: .rotationY)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
...@@ -500,7 +500,7 @@ extension Motion { ...@@ -500,7 +500,7 @@ extension Motion {
*/ */
public static func spinZ(rotations: CGFloat) -> CABasicAnimation { public static func spinZ(rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotationZ) let animation = CABasicAnimation(keyPath: .rotationZ)
animation.toValue = NSNumber(floatLiteral: Double(CGFloat(M_PI) * 2 * rotations)) animation.toValue = NSNumber(value: Double(CGFloat(M_PI) * 2 * rotations))
return animation return animation
} }
...@@ -511,7 +511,7 @@ extension Motion { ...@@ -511,7 +511,7 @@ extension Motion {
*/ */
public static func scale(to scale: CGFloat) -> CABasicAnimation { public static func scale(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scale) let animation = CABasicAnimation(keyPath: .scale)
animation.toValue = NSNumber(floatLiteral: Double(scale)) animation.toValue = NSNumber(value: Double(scale))
return animation return animation
} }
...@@ -522,7 +522,7 @@ extension Motion { ...@@ -522,7 +522,7 @@ extension Motion {
*/ */
public static func scaleX(to scale: CGFloat) -> CABasicAnimation { public static func scaleX(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleX) let animation = CABasicAnimation(keyPath: .scaleX)
animation.toValue = NSNumber(floatLiteral: Double(scale)) animation.toValue = NSNumber(value: Double(scale))
return animation return animation
} }
...@@ -533,7 +533,7 @@ extension Motion { ...@@ -533,7 +533,7 @@ extension Motion {
*/ */
public static func scaleY(to scale: CGFloat) -> CABasicAnimation { public static func scaleY(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleY) let animation = CABasicAnimation(keyPath: .scaleY)
animation.toValue = NSNumber(floatLiteral: Double(scale)) animation.toValue = NSNumber(value: Double(scale))
return animation return animation
} }
...@@ -544,7 +544,7 @@ extension Motion { ...@@ -544,7 +544,7 @@ extension Motion {
*/ */
public static func scaleZ(to scale: CGFloat) -> CABasicAnimation { public static func scaleZ(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleZ) let animation = CABasicAnimation(keyPath: .scaleZ)
animation.toValue = NSNumber(floatLiteral: Double(scale)) animation.toValue = NSNumber(value: Double(scale))
return animation return animation
} }
...@@ -566,7 +566,7 @@ extension Motion { ...@@ -566,7 +566,7 @@ extension Motion {
*/ */
public static func translateX(to translation: CGFloat) -> CABasicAnimation { public static func translateX(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationX) let animation = CABasicAnimation(keyPath: .translationX)
animation.toValue = NSNumber(floatLiteral: Double(translation)) animation.toValue = NSNumber(value: Double(translation))
return animation return animation
} }
...@@ -577,7 +577,7 @@ extension Motion { ...@@ -577,7 +577,7 @@ extension Motion {
*/ */
public static func translateY(to translation: CGFloat) -> CABasicAnimation { public static func translateY(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationY) let animation = CABasicAnimation(keyPath: .translationY)
animation.toValue = NSNumber(floatLiteral: Double(translation)) animation.toValue = NSNumber(value: Double(translation))
return animation return animation
} }
...@@ -588,7 +588,7 @@ extension Motion { ...@@ -588,7 +588,7 @@ extension Motion {
*/ */
public static func translateZ(to translation: CGFloat) -> CABasicAnimation { public static func translateZ(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationZ) let animation = CABasicAnimation(keyPath: .translationZ)
animation.toValue = NSNumber(floatLiteral: Double(translation)) animation.toValue = NSNumber(value: Double(translation))
return animation return animation
} }
......
...@@ -174,8 +174,6 @@ extension UIView { ...@@ -174,8 +174,6 @@ extension UIView {
v.transform = transform v.transform = transform
v.backgroundColor = backgroundColor v.backgroundColor = backgroundColor
print(motionRotationAngle)
isHidden = true isHidden = true
(self as? Pulseable)?.pulse.pulseLayer?.isHidden = false (self as? Pulseable)?.pulse.pulseLayer?.isHidden = false
...@@ -290,10 +288,10 @@ extension MotionTransition: UIViewControllerAnimatedTransitioning { ...@@ -290,10 +288,10 @@ extension MotionTransition: UIViewControllerAnimatedTransitioning {
prepareToViewController() prepareToViewController()
prepareFromViewController() prepareFromViewController()
prepareContainerView() prepareContainerView()
prepareTransitionSnapshot()
prepareTransitionView() prepareTransitionView()
prepareTransitionBackgroundView() prepareTransitionBackgroundView()
prepareTransitionSnapshot() prepareTransitionToView()
prepareToView()
prepareTransitionAnimation() prepareTransitionAnimation()
} }
...@@ -322,9 +320,16 @@ extension MotionTransition { ...@@ -322,9 +320,16 @@ extension MotionTransition {
containerView = transitionContext.containerView containerView = transitionContext.containerView
} }
fileprivate func prepareTransitionSnapshot() {
transitionSnapshot = fromView.motionTransitionSnapshot(afterUpdates: true)
transitionSnapshot.frame = containerView.bounds
containerView.addSubview(transitionSnapshot)
}
fileprivate func prepareTransitionView() { fileprivate func prepareTransitionView() {
transitionView.frame = containerView.bounds transitionView.frame = containerView.bounds
containerView.addSubview(transitionView) containerView.insertSubview(transitionView, belowSubview: transitionSnapshot)
} }
fileprivate func prepareTransitionBackgroundView() { fileprivate func prepareTransitionBackgroundView() {
...@@ -333,24 +338,29 @@ extension MotionTransition { ...@@ -333,24 +338,29 @@ extension MotionTransition {
transitionView.addSubview(transitionBackgroundView) transitionView.addSubview(transitionBackgroundView)
} }
fileprivate func prepareTransitionSnapshot() { fileprivate func prepareTransitionToView() {
transitionSnapshot = fromView.motionTransitionSnapshot(afterUpdates: true)
transitionSnapshot.frame = containerView.bounds
transitionView.addSubview(transitionSnapshot)
}
fileprivate func prepareToView() {
if isPresenting { if isPresenting {
containerView.insertSubview(toView, belowSubview: transitionView) containerView.insertSubview(toView, belowSubview: transitionView)
} }
toView.isHidden = false
toView.updateConstraints() toView.updateConstraints()
toView.setNeedsLayout() toView.setNeedsLayout()
toView.layoutIfNeeded() toView.layoutIfNeeded()
toView.isHidden = false
} }
fileprivate func prepareTransitionAnimation() { fileprivate func prepareTransitionAnimation() {
addTransitionAnimations()
addBackgroundMotionAnimation()
cleanupAnimation()
cleanupFromView()
cleanupTransitionSnapshot()
}
}
extension MotionTransition {
fileprivate func addTransitionAnimations() {
for fv in fromSubviews { for fv in fromSubviews {
for tv in toSubviews { for tv in toSubviews {
if tv.motionTransitionIdentifier == fv.motionTransitionIdentifier { if tv.motionTransitionIdentifier == fv.motionTransitionIdentifier {
...@@ -391,7 +401,7 @@ extension MotionTransition { ...@@ -391,7 +401,7 @@ extension MotionTransition {
snapshotChildAnimations.append(Motion.position(x: tv.bounds.width / 2, y: tv.bounds.height / 2)) 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.addSubview(snapshot)
Motion.delay(t) { Motion.delay(t) {
for ta in tv.motionTransitionAnimations { for ta in tv.motionTransitionAnimations {
...@@ -420,16 +430,8 @@ extension MotionTransition { ...@@ -420,16 +430,8 @@ extension MotionTransition {
} }
} }
} }
addBackgroundMotionAnimation()
cleanupAnimation()
cleanupFromView()
cleanupTransitionSnapshot()
} }
}
extension MotionTransition {
fileprivate func addBackgroundMotionAnimation() { fileprivate func addBackgroundMotionAnimation() {
transitionBackgroundView.motion(.backgroundColor(toView.backgroundColor ?? .clear), .duration(transitionDuration(using: transitionContext))) transitionBackgroundView.motion(.backgroundColor(toView.backgroundColor ?? .clear), .duration(transitionDuration(using: transitionContext)))
} }
......
/* /*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
/* /*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
/* /*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
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