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.
*
* Redistribution and use in source and binary forms, with or without
......
......@@ -86,7 +86,7 @@ private class FontLoader {
let bundle = Bundle(for: FontLoader.self)
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 {
let data = NSData(contentsOf: v as URL)!
......
......@@ -42,7 +42,7 @@ public struct Icon {
if nil == Icon.internalBundle {
Icon.internalBundle = Bundle(for: View.self)
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 {
Icon.internalBundle = v
}
......
......@@ -423,7 +423,7 @@ extension Motion {
*/
public static func rotation(angle: CGFloat) -> CABasicAnimation {
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
}
......@@ -434,7 +434,7 @@ extension Motion {
*/
public static func rotationX(angle: CGFloat) -> CABasicAnimation {
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
}
......@@ -445,7 +445,7 @@ extension Motion {
*/
public static func rotationY(angle: CGFloat) -> CABasicAnimation {
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
}
......@@ -456,7 +456,7 @@ extension Motion {
*/
public static func rotationZ(angle: CGFloat) -> CABasicAnimation {
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
}
......@@ -467,7 +467,7 @@ extension Motion {
*/
public static func spin(rotations: CGFloat) -> CABasicAnimation {
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
}
......@@ -478,7 +478,7 @@ extension Motion {
*/
public static func spinX(rotations: CGFloat) -> CABasicAnimation {
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
}
......@@ -489,7 +489,7 @@ extension Motion {
*/
public static func spinY(rotations: CGFloat) -> CABasicAnimation {
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
}
......@@ -500,7 +500,7 @@ extension Motion {
*/
public static func spinZ(rotations: CGFloat) -> CABasicAnimation {
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
}
......@@ -511,7 +511,7 @@ extension Motion {
*/
public static func scale(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scale)
animation.toValue = NSNumber(floatLiteral: Double(scale))
animation.toValue = NSNumber(value: Double(scale))
return animation
}
......@@ -522,7 +522,7 @@ extension Motion {
*/
public static func scaleX(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleX)
animation.toValue = NSNumber(floatLiteral: Double(scale))
animation.toValue = NSNumber(value: Double(scale))
return animation
}
......@@ -533,7 +533,7 @@ extension Motion {
*/
public static func scaleY(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleY)
animation.toValue = NSNumber(floatLiteral: Double(scale))
animation.toValue = NSNumber(value: Double(scale))
return animation
}
......@@ -544,7 +544,7 @@ extension Motion {
*/
public static func scaleZ(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleZ)
animation.toValue = NSNumber(floatLiteral: Double(scale))
animation.toValue = NSNumber(value: Double(scale))
return animation
}
......@@ -566,7 +566,7 @@ extension Motion {
*/
public static func translateX(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationX)
animation.toValue = NSNumber(floatLiteral: Double(translation))
animation.toValue = NSNumber(value: Double(translation))
return animation
}
......@@ -577,7 +577,7 @@ extension Motion {
*/
public static func translateY(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationY)
animation.toValue = NSNumber(floatLiteral: Double(translation))
animation.toValue = NSNumber(value: Double(translation))
return animation
}
......@@ -588,7 +588,7 @@ extension Motion {
*/
public static func translateZ(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationZ)
animation.toValue = NSNumber(floatLiteral: Double(translation))
animation.toValue = NSNumber(value: Double(translation))
return animation
}
......
......@@ -174,8 +174,6 @@ extension UIView {
v.transform = transform
v.backgroundColor = backgroundColor
print(motionRotationAngle)
isHidden = true
(self as? Pulseable)?.pulse.pulseLayer?.isHidden = false
......@@ -290,10 +288,10 @@ extension MotionTransition: UIViewControllerAnimatedTransitioning {
prepareToViewController()
prepareFromViewController()
prepareContainerView()
prepareTransitionSnapshot()
prepareTransitionView()
prepareTransitionBackgroundView()
prepareTransitionSnapshot()
prepareToView()
prepareTransitionToView()
prepareTransitionAnimation()
}
......@@ -322,9 +320,16 @@ extension MotionTransition {
containerView = transitionContext.containerView
}
fileprivate func prepareTransitionSnapshot() {
transitionSnapshot = fromView.motionTransitionSnapshot(afterUpdates: true)
transitionSnapshot.frame = containerView.bounds
containerView.addSubview(transitionSnapshot)
}
fileprivate func prepareTransitionView() {
transitionView.frame = containerView.bounds
containerView.addSubview(transitionView)
containerView.insertSubview(transitionView, belowSubview: transitionSnapshot)
}
fileprivate func prepareTransitionBackgroundView() {
......@@ -333,24 +338,29 @@ extension MotionTransition {
transitionView.addSubview(transitionBackgroundView)
}
fileprivate func prepareTransitionSnapshot() {
transitionSnapshot = fromView.motionTransitionSnapshot(afterUpdates: true)
transitionSnapshot.frame = containerView.bounds
transitionView.addSubview(transitionSnapshot)
}
fileprivate func prepareToView() {
fileprivate func prepareTransitionToView() {
if isPresenting {
containerView.insertSubview(toView, belowSubview: transitionView)
}
toView.isHidden = false
toView.updateConstraints()
toView.setNeedsLayout()
toView.layoutIfNeeded()
toView.isHidden = false
}
fileprivate func prepareTransitionAnimation() {
addTransitionAnimations()
addBackgroundMotionAnimation()
cleanupAnimation()
cleanupFromView()
cleanupTransitionSnapshot()
}
}
extension MotionTransition {
fileprivate func addTransitionAnimations() {
for fv in fromSubviews {
for tv in toSubviews {
if tv.motionTransitionIdentifier == fv.motionTransitionIdentifier {
......@@ -391,7 +401,7 @@ extension MotionTransition {
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)
transitionView.addSubview(snapshot)
Motion.delay(t) {
for ta in tv.motionTransitionAnimations {
......@@ -420,16 +430,8 @@ extension MotionTransition {
}
}
}
addBackgroundMotionAnimation()
cleanupAnimation()
cleanupFromView()
cleanupTransitionSnapshot()
}
}
extension MotionTransition {
fileprivate func addBackgroundMotionAnimation() {
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.
*
* 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.
*
* 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.
*
* 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