Commit 267e5d34 by Daniel Dahan

updated left and right animations when changing the SideNavigationViewController's width

parent 697bc98a
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.34.10</string> <string>1.35.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -107,6 +107,9 @@ public protocol SideNavigationViewControllerDelegate { ...@@ -107,6 +107,9 @@ public protocol SideNavigationViewControllerDelegate {
@objc(SideNavigationViewController) @objc(SideNavigationViewController)
public class SideNavigationViewController: UIViewController, UIGestureRecognizerDelegate { public class SideNavigationViewController: UIViewController, UIGestureRecognizerDelegate {
private var animating: Bool = false
/** /**
A CGFloat property that is used internally to track A CGFloat property that is used internally to track
the original (x) position of the container view when panning. the original (x) position of the container view when panning.
...@@ -367,39 +370,59 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -367,39 +370,59 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public func setLeftViewWidth(width: CGFloat, var hidden: Bool, animated: Bool, duration: NSTimeInterval = 0.5) { public func setLeftViewWidth(width: CGFloat, var hidden: Bool, animated: Bool, duration: NSTimeInterval = 0.5) {
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
leftViewWidth = width leftViewWidth = width
layoutSubviews()
if openedRightView { if openedRightView {
hidden = true hidden = true
} }
if animated { if animated {
animating = true
v.shadowPath = nil
v.shadowPathAutoSizeEnabled = false
if hidden { if hidden {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { animations: { [unowned self] in
v.width = width v.bounds.size.width = width
v.position = CGPointMake(-width / 2, v.height / 2) v.position.x = -width / 2
}) { _ in self.mainViewController.view.alpha = 1
}) { [unowned self] _ in
v.shadowPathAutoSizeEnabled = true
self.animating = false
self.layoutSubviews()
self.hideView(v) self.hideView(v)
} }
} else { } else {
showView(v)
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { animations: { [unowned self] in
v.width = width v.bounds.size.width = width
v.position = CGPointMake(width / 2, v.height / 2) v.position.x = width / 2
}) self.mainViewController.view.alpha = 0.5
}) { [unowned self] _ in
v.shadowPathAutoSizeEnabled = true
self.animating = false
self.layoutSubviews()
self.showView(v)
}
} }
} else { } else {
v.width = width v.bounds.size.width = width
if hidden { if hidden {
hideView(v) hideView(v)
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position.x = -v.width / 2
mainViewController.view.alpha = 1
} else { } else {
v.shadowPath = nil
v.shadowPathAutoSizeEnabled = false
showView(v) showView(v)
v.position = CGPointMake(v.width / 2, v.height / 2) v.position.x = width / 2
mainViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true
} }
layoutSubviews()
} }
} }
} }
...@@ -416,38 +439,57 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -416,38 +439,57 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public func setRightViewWidth(width: CGFloat, var hidden: Bool, animated: Bool, duration: NSTimeInterval = 0.5) { public func setRightViewWidth(width: CGFloat, var hidden: Bool, animated: Bool, duration: NSTimeInterval = 0.5) {
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
rightViewWidth = width rightViewWidth = width
layoutSubviews()
if openedLeftView { if openedLeftView {
hidden = true hidden = true
} }
if animated { if animated {
animating = true
v.shadowPath = nil
v.shadowPathAutoSizeEnabled = false
if hidden { if hidden {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { animations: { [unowned self] in
v.width = width v.bounds.size.width = width
v.position = CGPointMake(self.view.bounds.width + width / 2, v.height / 2) v.position.x = self.view.bounds.width + width / 2
}) { _ in self.mainViewController.view.alpha = 1
}) { [unowned self] _ in
v.shadowPathAutoSizeEnabled = true
self.animating = false
self.layoutSubviews()
self.hideView(v) self.hideView(v)
} }
} else { } else {
showView(v)
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { animations: { [unowned self] in
v.width = width v.bounds.size.width = width
v.position = CGPointMake(self.view.bounds.width - width / 2, v.height / 2) v.position.x = self.view.bounds.width - width / 2
}) self.mainViewController.view.alpha = 0.5
}) { [unowned self] _ in
v.shadowPathAutoSizeEnabled = true
self.animating = false
self.layoutSubviews()
self.showView(v)
}
} }
} else { } else {
v.width = width v.bounds.size.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.x = view.bounds.width + v.width / 2
mainViewController.view.alpha = 1
} else { } else {
v.shadowPath = nil
v.shadowPathAutoSizeEnabled = false
showView(v) showView(v)
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) v.position.x = view.bounds.width - width / 2
mainViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true
} }
layoutSubviews()
} }
} }
} }
...@@ -489,7 +531,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -489,7 +531,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
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: { [unowned self] in animations: { [unowned self] in
v.position = CGPointMake(v.width / 2, v.height / 2) v.position.x = v.width / 2
self.mainViewController.view.alpha = 0.5 self.mainViewController.view.alpha = 0.5
}) { _ in }) { _ in
self.delegate?.sideNavigationViewDidOpen?(self, position: .Left) self.delegate?.sideNavigationViewDidOpen?(self, position: .Left)
...@@ -513,7 +555,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -513,7 +555,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
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: { [unowned self] in animations: { [unowned self] in
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) v.position.x = self.view.bounds.width - v.width / 2
self.mainViewController.view.alpha = 0.5 self.mainViewController.view.alpha = 0.5
}) { _ in }) { _ in
self.delegate?.sideNavigationViewDidOpen?(self, position: .Right) self.delegate?.sideNavigationViewDidOpen?(self, position: .Right)
...@@ -534,7 +576,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -534,7 +576,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
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: { [unowned self] in animations: { [unowned self] in
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position.x = -v.width / 2
self.mainViewController.view.alpha = 1 self.mainViewController.view.alpha = 1
}) { _ in }) { _ in
self.toggleStatusBar() self.toggleStatusBar()
...@@ -557,7 +599,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -557,7 +599,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
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: { [unowned self] in animations: { [unowned self] in
v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2) v.position.x = self.view.bounds.width + v.width / 2
self.mainViewController.view.alpha = 1 self.mainViewController.view.alpha = 1
}) { _ in }) { _ in
self.toggleStatusBar() self.toggleStatusBar()
...@@ -877,27 +919,29 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -877,27 +919,29 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/// Layout subviews. /// Layout subviews.
private func layoutSubviews() { private func layoutSubviews() {
toggleStatusBar() if !animating {
toggleStatusBar()
if let v: MaterialView = leftView {
v.width = leftViewWidth if let v: MaterialView = leftView {
v.height = view.bounds.height v.width = leftViewWidth
leftViewThreshold = leftViewWidth / 2 v.height = view.bounds.height
if let vc: UIViewController = leftViewController { leftViewThreshold = leftViewWidth / 2
vc.view.frame.size.width = v.width if let vc: UIViewController = leftViewController {
vc.view.frame.size.height = v.height vc.view.frame.size.width = v.width
vc.view.center = CGPointMake(v.width / 2, v.height / 2) vc.view.frame.size.height = v.height
vc.view.center = CGPointMake(v.width / 2, v.height / 2)
}
} }
}
if let v: MaterialView = rightView {
if let v: MaterialView = rightView { v.width = rightViewWidth
v.width = rightViewWidth v.height = view.bounds.height
v.height = view.bounds.height rightViewThreshold = view.bounds.width - rightViewWidth / 2
rightViewThreshold = view.bounds.width - rightViewWidth / 2 if let vc: UIViewController = rightViewController {
if let vc: UIViewController = rightViewController { vc.view.frame.size.width = v.width
vc.view.frame.size.width = v.width vc.view.frame.size.height = v.height
vc.view.frame.size.height = v.height vc.view.center = CGPointMake(v.width / 2, v.height / 2)
vc.view.center = CGPointMake(v.width / 2, v.height / 2) }
} }
} }
} }
......
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