Commit 74ff1a4d by Daniel Dahan

fixed SideNavigation quick swipe close issue

parent 80b03f9c
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; }; 9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* LeftViewController.swift */; }; 9642FA331C1B909700022BC6 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* LeftViewController.swift */; };
967585381C569AA9001E4268 /* RightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967585371C569AA9001E4268 /* RightViewController.swift */; }; 967585381C569AA9001E4268 /* RightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967585371C569AA9001E4268 /* RightViewController.swift */; };
96DBA7211C61103200844821 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96DBA7201C61103200844821 /* Material.framework */; };
96DBA7221C61103200844821 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96DBA7201C61103200844821 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -22,6 +24,7 @@ ...@@ -22,6 +24,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96DBA7221C61103200844821 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -37,6 +40,7 @@ ...@@ -37,6 +40,7 @@
9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* LeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftViewController.swift; sourceTree = "<group>"; }; 9642FA321C1B909700022BC6 /* LeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftViewController.swift; sourceTree = "<group>"; };
967585371C569AA9001E4268 /* RightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RightViewController.swift; sourceTree = "<group>"; }; 967585371C569AA9001E4268 /* RightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RightViewController.swift; sourceTree = "<group>"; };
96DBA7201C61103200844821 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -44,6 +48,7 @@ ...@@ -44,6 +48,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96DBA7211C61103200844821 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -53,6 +58,7 @@ ...@@ -53,6 +58,7 @@
9642FA0E1C1B50E700022BC6 = { 9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96DBA7201C61103200844821 /* Material.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */, 9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */, 9642FA181C1B50E700022BC6 /* Products */,
); );
......
...@@ -332,10 +332,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -332,10 +332,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
MaterialAnimation.animationDisabled { [unowned self] in v.width = self.leftViewWidth
v.width = self.leftViewWidth v.height = self.view.bounds.height
v.height = self.view.bounds.height
}
leftViewThreshold = leftViewWidth / 2 leftViewThreshold = leftViewWidth / 2
if let vc: UIViewController = leftViewController { if let vc: UIViewController = leftViewController {
vc.view.frame.size.width = v.width vc.view.frame.size.width = v.width
...@@ -345,10 +343,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -345,10 +343,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
MaterialAnimation.animationDisabled { [unowned self] in v.width = self.rightViewWidth
v.width = self.rightViewWidth v.height = self.view.bounds.height
v.height = self.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
...@@ -360,9 +356,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -360,9 +356,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) { public override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
MaterialAnimation.animationDisabled { [unowned self] in v.x = self.view.bounds.height - (self.openedRightView ? self.rightViewWidth : 0)
v.x = self.view.bounds.height - (self.openedRightView ? self.rightViewWidth : 0)
}
} }
} }
...@@ -417,17 +411,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -417,17 +411,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = (hidden ? -width : width) / 2 let w: CGFloat = (hidden ? -width : width) / 2
if animated { if animated {
MaterialAnimation.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
v.width = width v.width = width
v.position.x = w v.position.x = w
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = false self.userInteractionEnabled = false
} }
} else { } else {
MaterialAnimation.animationDisabled { v.width = width
v.width = width v.position.x = w
v.position.x = w
}
} }
} }
} }
...@@ -449,17 +441,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -449,17 +441,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = (hidden ? -width : width) / 2 let w: CGFloat = (hidden ? -width : width) / 2
if animated { if animated {
MaterialAnimation.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
v.width = width v.width = width
v.position.x = w v.position.x = w
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = false self.userInteractionEnabled = false
} }
} else { } else {
MaterialAnimation.animationDisabled { v.width = width
v.width = width v.position.x = w
v.position.x = w
}
} }
} }
} }
...@@ -501,10 +491,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -501,10 +491,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = false backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self, position: .Left) delegate?.sideNavigationViewWillOpen?(self, position: .Left)
MaterialAnimation.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: {
v.position = CGPointMake(v.width / 2, v.height / 2) v.position = CGPointMake(v.width / 2, v.height / 2)
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showDepth(v) self.showDepth(v)
self.delegate?.sideNavigationViewDidOpen?(self, position: .Left) self.delegate?.sideNavigationViewDidOpen?(self, position: .Left)
...@@ -528,10 +518,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -528,10 +518,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = false backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self, position: .Right) delegate?.sideNavigationViewWillOpen?(self, position: .Right)
MaterialAnimation.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: {
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)
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showDepth(v) self.showDepth(v)
self.delegate?.sideNavigationViewDidOpen?(self, position: .Right) self.delegate?.sideNavigationViewDidOpen?(self, position: .Right)
...@@ -553,10 +543,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -553,10 +543,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
delegate?.sideNavigationViewWillClose?(self, position: .Left) delegate?.sideNavigationViewWillClose?(self, position: .Left)
MaterialAnimation.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: {
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position = CGPointMake(-v.width / 2, v.height / 2)
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = true self.userInteractionEnabled = true
self.hideDepth(v) self.hideDepth(v)
self.hideView(v) self.hideView(v)
...@@ -579,10 +569,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -579,10 +569,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
delegate?.sideNavigationViewWillClose?(self, position: .Right) delegate?.sideNavigationViewWillClose?(self, position: .Right)
MaterialAnimation.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: {
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)
}) { [unowned self] in }) { _ in
self.userInteractionEnabled = true self.userInteractionEnabled = true
self.hideDepth(v) self.hideDepth(v)
self.hideView(v) self.hideView(v)
...@@ -629,17 +619,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -629,17 +619,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = v.width let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in v.position.x = self.originalX + translationX < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : self.originalX + translationX
v.position.x = self.originalX + translationX < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : self.originalX + translationX delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Right)
self.delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Right)
}
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Right) delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Right)
if v.x >= rightViewThreshold { if v.x >= rightViewThreshold || x > 1000 {
closeRightView(x) closeRightView(x)
} else { } else {
openRightView(x) openRightView(x)
...@@ -666,17 +654,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -666,17 +654,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = v.width let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in v.position.x = self.originalX + translationX > (w / 2) ? (w / 2) : self.originalX + translationX
v.position.x = self.originalX + translationX > (w / 2) ? (w / 2) : self.originalX + translationX delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Left)
self.delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Left)
}
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Left) delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Left)
if v.x <= -leftViewWidth + leftViewThreshold { if v.x <= -leftViewWidth + leftViewThreshold || x < -1000 {
closeLeftView(x) closeLeftView(x)
} else { } else {
openLeftView(x) openLeftView(x)
...@@ -753,11 +739,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -753,11 +739,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftView!.backgroundColor = MaterialColor.clear leftView!.backgroundColor = MaterialColor.clear
view.addSubview(leftView!) view.addSubview(leftView!)
MaterialAnimation.animationDisabled { [unowned self] in leftView!.hidden = true
self.leftView!.hidden = true leftView!.position.x = -self.leftViewWidth / 2
self.leftView!.position.x = -self.leftViewWidth / 2 leftView!.zPosition = 1000
self.leftView!.zPosition = 1000
}
} }
} }
...@@ -769,11 +753,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -769,11 +753,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
rightView!.backgroundColor = MaterialColor.clear rightView!.backgroundColor = MaterialColor.clear
view.addSubview(rightView!) view.addSubview(rightView!)
MaterialAnimation.animationDisabled { [unowned self] in rightView!.hidden = true
self.rightView!.hidden = true rightView!.position.x = self.view.bounds.width + self.rightViewWidth / 2
self.rightView!.position.x = self.view.bounds.width + self.rightViewWidth / 2 rightView!.zPosition = 1000
self.rightView!.zPosition = 1000
}
} }
} }
...@@ -906,9 +888,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -906,9 +888,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func showDepth(container: MaterialView) { private func showDepth(container: MaterialView) {
MaterialAnimation.animationDisabled { [unowned self] in container.depth = self.depth
container.depth = self.depth
}
} }
/** /**
...@@ -916,9 +896,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -916,9 +896,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func hideDepth(container: MaterialView) { private func hideDepth(container: MaterialView) {
MaterialAnimation.animationDisabled { container.depth = .None
container.depth = .None
}
} }
/** /**
...@@ -926,9 +904,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -926,9 +904,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func showView(container: UIView) { private func showView(container: UIView) {
MaterialAnimation.animationDisabled { container.hidden = false
container.hidden = false
}
} }
/** /**
...@@ -936,8 +912,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -936,8 +912,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
- Parameter container: A container view. - Parameter container: A container view.
*/ */
private func hideView(container: UIView) { private func hideView(container: UIView) {
MaterialAnimation.animationDisabled { container.hidden = true
container.hidden = true
}
} }
} }
\ No newline at end of file
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