Commit 697bc98a by Daniel Dahan

updated SideNavigationViewController to utilize alpha for backdrop animation

parent 1fc64c08
...@@ -52,14 +52,12 @@ class AppMenuViewController: MenuViewController { ...@@ -52,14 +52,12 @@ class AppMenuViewController: MenuViewController {
override func openMenu(completion: (() -> Void)? = nil) { override func openMenu(completion: (() -> Void)? = nil) {
super.openMenu(completion) super.openMenu(completion)
sideNavigationViewController?.enabled = false sideNavigationViewController?.enabled = false
mainViewController.view.alpha = 0.5
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(0.125)) (menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(0.125))
} }
override func closeMenu(completion: (() -> Void)? = nil) { override func closeMenu(completion: (() -> Void)? = nil) {
super.closeMenu(completion) super.closeMenu(completion)
sideNavigationViewController?.enabled = true sideNavigationViewController?.enabled = true
mainViewController.view.alpha = 1
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(-0.125)) (menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(-0.125))
} }
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.34.10' s.version = '1.35.0'
s.license = 'BSD' s.license = 'BSD'
s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.' s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -378,8 +378,8 @@ ...@@ -378,8 +378,8 @@
96442ADC1C28EF1400C3C574 /* TableView */, 96442ADC1C28EF1400C3C574 /* TableView */,
96CC08891C7FEBE10034FF84 /* CollectionView */, 96CC08891C7FEBE10034FF84 /* CollectionView */,
965C58BD1C6B8D3300CFB4E1 /* Grid */, 965C58BD1C6B8D3300CFB4E1 /* Grid */,
96A71E921C6FBC2900C0C4AE /* Menu */,
96A71EC51C6FFEF300C0C4AE /* Switch */, 96A71EC51C6FFEF300C0C4AE /* Switch */,
96A71E921C6FBC2900C0C4AE /* Menu */,
96CC08561C7E0EC00034FF84 /* ControlView */, 96CC08561C7E0EC00034FF84 /* ControlView */,
96D88C541C132A7700B91418 /* StatusBar */, 96D88C541C132A7700B91418 /* StatusBar */,
9626C2DB1C794FBB007CA8E0 /* SearchBar */, 9626C2DB1C794FBB007CA8E0 /* SearchBar */,
......
...@@ -129,10 +129,9 @@ public class MenuViewController: UIViewController { ...@@ -129,10 +129,9 @@ public class MenuViewController: UIViewController {
*/ */
public func openMenu(completion: (() -> Void)? = nil) { public func openMenu(completion: (() -> Void)? = nil) {
if true == userInteractionEnabled { if true == userInteractionEnabled {
menuView.open { [weak self] in userInteractionEnabled = false
self?.userInteractionEnabled = false mainViewController.view.alpha = 0.5
completion?() menuView.open(completion)
}
} }
} }
...@@ -143,10 +142,9 @@ public class MenuViewController: UIViewController { ...@@ -143,10 +142,9 @@ public class MenuViewController: UIViewController {
*/ */
public func closeMenu(completion: (() -> Void)? = nil) { public func closeMenu(completion: (() -> Void)? = nil) {
if false == userInteractionEnabled { if false == userInteractionEnabled {
menuView.close { [weak self] in userInteractionEnabled = true
self?.userInteractionEnabled = true mainViewController.view.alpha = 1
completion?() menuView.close(completion)
}
} }
} }
......
...@@ -126,14 +126,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -126,14 +126,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private var tapGesture: UITapGestureRecognizer? private var tapGesture: UITapGestureRecognizer?
/** /**
A CAShapeLayer property that is used as the backdrop when
opened. To change the opacity and color of the backdrop,
it is recommended to use the backdropOpcaity property and
backdropColor property, respectively.
*/
public private(set) lazy var backdropLayer: CAShapeLayer = CAShapeLayer()
/**
A CGFloat property that accesses the leftView threshold of A CGFloat property that accesses the leftView threshold of
the SideNavigationViewController. When the panning gesture has the SideNavigationViewController. When the panning gesture has
ended, if the position is beyond the threshold, ended, if the position is beyond the threshold,
...@@ -250,20 +242,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -250,20 +242,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
public private(set) var rightView: MaterialView? public private(set) var rightView: MaterialView?
/// A CGFloat property to set the backdropLayer color opacity.
public var backdropOpacity: CGFloat = 0.5 {
didSet {
backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor
}
}
/// A UIColor property to set the backdropLayer color.
public var backdropColor: UIColor? {
didSet {
backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor
}
}
/// Indicates whether the leftView or rightView is opened. /// Indicates whether the leftView or rightView is opened.
public var opened: Bool { public var opened: Bool {
return openedLeftView || openedRightView return openedLeftView || openedRightView
...@@ -372,7 +350,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -372,7 +350,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self.mainViewController.removeFromParentViewController() self.mainViewController.removeFromParentViewController()
self.mainViewController = toViewController self.mainViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view) self.view.sendSubviewToBack(self.mainViewController.view)
self.userInteractionEnabled = !self.opened
completion?(result) completion?(result)
}) })
} }
...@@ -394,8 +371,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -394,8 +371,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if openedRightView { if openedRightView {
hidden = true hidden = true
} else {
backdropLayer.hidden = hidden
} }
if animated { if animated {
...@@ -405,8 +380,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -405,8 +380,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
v.width = width v.width = width
v.position = CGPointMake(-width / 2, v.height / 2) v.position = CGPointMake(-width / 2, v.height / 2)
}) { _ in }) { _ in
self.userInteractionEnabled = true
self.hideDepth(v)
self.hideView(v) self.hideView(v)
} }
} else { } else {
...@@ -415,21 +388,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -415,21 +388,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
animations: { animations: {
v.width = width v.width = width
v.position = CGPointMake(width / 2, v.height / 2) v.position = CGPointMake(width / 2, v.height / 2)
}) { _ in })
self.userInteractionEnabled = true
self.showDepth(v)
}
} }
} else { } else {
v.width = width v.width = width
if hidden { if hidden {
hideView(v) hideView(v)
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position = CGPointMake(-v.width / 2, v.height / 2)
hideDepth(v)
} else { } else {
showView(v) showView(v)
v.position = CGPointMake(v.width / 2, v.height / 2) v.position = CGPointMake(v.width / 2, v.height / 2)
showDepth(v)
} }
} }
} }
...@@ -452,8 +420,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -452,8 +420,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if openedLeftView { if openedLeftView {
hidden = true hidden = true
} else {
backdropLayer.hidden = hidden
} }
if animated { if animated {
...@@ -463,8 +429,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -463,8 +429,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
v.width = width v.width = width
v.position = CGPointMake(self.view.bounds.width + width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width + width / 2, v.height / 2)
}) { _ in }) { _ in
self.userInteractionEnabled = true
self.hideDepth(v)
self.hideView(v) self.hideView(v)
} }
} else { } else {
...@@ -473,21 +437,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -473,21 +437,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
animations: { animations: {
v.width = width v.width = width
v.position = CGPointMake(self.view.bounds.width - width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width - width / 2, v.height / 2)
}) { _ in })
self.userInteractionEnabled = true
self.showDepth(v)
}
} }
} else { } else {
v.width = width v.width = width
if hidden { if hidden {
hideView(v) hideView(v)
v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2)
hideDepth(v)
} else { } else {
showView(v) showView(v)
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2)
showDepth(v)
} }
} }
} }
...@@ -527,15 +486,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -527,15 +486,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
showView(v) showView(v)
backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self, position: .Left) delegate?.sideNavigationViewWillOpen?(self, position: .Left)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: { [unowned self] in
v.position = CGPointMake(v.width / 2, v.height / 2) v.position = CGPointMake(v.width / 2, v.height / 2)
self.mainViewController.view.alpha = 0.5
}) { _ in }) { _ in
self.userInteractionEnabled = false
self.showDepth(v)
self.delegate?.sideNavigationViewDidOpen?(self, position: .Left) self.delegate?.sideNavigationViewDidOpen?(self, position: .Left)
} }
} }
...@@ -554,17 +510,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -554,17 +510,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
showView(v) showView(v)
backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self, position: .Right) delegate?.sideNavigationViewWillOpen?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: { [unowned self] in
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2)
}) { _ in self.mainViewController.view.alpha = 0.5
self.userInteractionEnabled = false }) { _ in
self.showDepth(v) self.delegate?.sideNavigationViewDidOpen?(self, position: .Right)
self.delegate?.sideNavigationViewDidOpen?(self, position: .Right) }
}
} }
} }
} }
...@@ -577,18 +530,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -577,18 +530,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
public func closeLeftView(velocity: CGFloat = 0) { public func closeLeftView(velocity: CGFloat = 0) {
if enabledLeftView { if enabledLeftView {
backdropLayer.hidden = true
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
self.hideDepth(v)
delegate?.sideNavigationViewWillClose?(self, position: .Left) delegate?.sideNavigationViewWillClose?(self, position: .Left)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: { [unowned self] in
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position = CGPointMake(-v.width / 2, v.height / 2)
self.mainViewController.view.alpha = 1
}) { _ in }) { _ in
self.toggleStatusBar() self.toggleStatusBar()
self.userInteractionEnabled = true
self.hideView(v) self.hideView(v)
self.delegate?.sideNavigationViewDidClose?(self, position: .Left) self.delegate?.sideNavigationViewDidClose?(self, position: .Left)
} }
...@@ -604,18 +553,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -604,18 +553,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
public func closeRightView(velocity: CGFloat = 0) { public func closeRightView(velocity: CGFloat = 0) {
if enabledRightView { if enabledRightView {
backdropLayer.hidden = true
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
self.hideDepth(v)
delegate?.sideNavigationViewWillClose?(self, position: .Right) delegate?.sideNavigationViewWillClose?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: { [unowned self] in
v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2)
self.mainViewController.view.alpha = 1
}) { _ in }) { _ in
self.toggleStatusBar() self.toggleStatusBar()
self.userInteractionEnabled = true
self.hideView(v) self.hideView(v)
self.delegate?.sideNavigationViewDidClose?(self, position: .Right) self.delegate?.sideNavigationViewDidClose?(self, position: .Right)
} }
...@@ -645,12 +590,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -645,12 +590,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// Animate the panel. // Animate the panel.
switch recognizer.state { switch recognizer.state {
case .Began: case .Began:
backdropLayer.hidden = false
originalX = v.position.x originalX = v.position.x
toggleStatusBar(true) toggleStatusBar(true)
showView(v) showView(v)
showDepth(v)
delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Right) delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Right)
case .Changed: case .Changed:
...@@ -680,12 +623,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -680,12 +623,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// Animate the panel. // Animate the panel.
switch recognizer.state { switch recognizer.state {
case .Began: case .Began:
backdropLayer.hidden = false
originalX = v.position.x originalX = v.position.x
toggleStatusBar(true) toggleStatusBar(true)
showView(v) showView(v)
showDepth(v)
delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Left) delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Left)
case .Changed: case .Changed:
...@@ -738,7 +679,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -738,7 +679,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/// A method that generally prepares the SideNavigationViewController. /// A method that generally prepares the SideNavigationViewController.
private func prepareView() { private func prepareView() {
prepareBackdropLayer()
prepareMainViewController() prepareMainViewController()
prepareLeftView() prepareLeftView()
prepareRightView() prepareRightView()
...@@ -803,14 +743,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -803,14 +743,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
} }
/// A method that prepares the backdropLayer.
private func prepareBackdropLayer() {
backdropColor = MaterialColor.black
backdropLayer.zPosition = 1500
backdropLayer.hidden = true
view.layer.addSublayer(backdropLayer)
}
/** /**
A method that adds the passed in controller as a child of A method that adds the passed in controller as a child of
the SideNavigationViewController within the passed in the SideNavigationViewController within the passed in
...@@ -924,26 +856,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -924,26 +856,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
A method that adds the depth to the passed in container view.
- Parameter container: A container view.
*/
private func showDepth(container: MaterialView) {
container.depth = depth
}
/**
A method that removes the depth from the passed in container view.
- Parameter container: A container view.
*/
private func hideDepth(container: MaterialView) {
container.depth = .None
}
/**
A method that shows a view. A method that shows a view.
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func showView(container: UIView) { private func showView(container: MaterialView) {
userInteractionEnabled = false
container.depth = depth
container.hidden = false container.hidden = false
} }
...@@ -951,7 +869,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -951,7 +869,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
A method that hides a view. A method that hides a view.
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func hideView(container: UIView) { private func hideView(container: MaterialView) {
userInteractionEnabled = true
container.depth = .None
container.hidden = true container.hidden = true
} }
...@@ -959,10 +879,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -959,10 +879,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private func layoutSubviews() { private func layoutSubviews() {
toggleStatusBar() toggleStatusBar()
MaterialAnimation.animationDisabled { [unowned self] in
self.backdropLayer.frame = self.view.bounds
}
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
v.width = leftViewWidth v.width = leftViewWidth
v.height = view.bounds.height v.height = view.bounds.height
......
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