Commit 4e2e0f24 by danieldahan

updated to latest

parent 9a2e6a45
...@@ -20,14 +20,14 @@ import UIKit ...@@ -20,14 +20,14 @@ import UIKit
public class BasicCollectionViewCell : MaterialPanCollectionViewCell { public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
/** /**
:name: titleLayer :name: titleLabel
*/ */
public private(set) lazy var titleLayer: MaterialTextLayer = MaterialTextLayer() public private(set) lazy var titleLabel: MaterialLabel = MaterialLabel()
/** /**
:name: detailLayer :name: detailLabel
*/ */
public private(set) lazy var detailLayer: MaterialTextLayer = MaterialTextLayer() public private(set) lazy var detailLabel: MaterialLabel = MaterialLabel()
/** /**
:name: prepareView :name: prepareView
...@@ -36,9 +36,9 @@ public class BasicCollectionViewCell : MaterialPanCollectionViewCell { ...@@ -36,9 +36,9 @@ public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
super.prepareView() super.prepareView()
// title // title
layer.addSublayer(titleLayer) addSubview(titleLabel)
// detail // detail
layer.addSublayer(detailLayer) addSubview(detailLabel)
} }
} }
\ No newline at end of file
...@@ -364,9 +364,9 @@ public class MaterialButton : UIButton { ...@@ -364,9 +364,9 @@ public class MaterialButton : UIButton {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}) }
} }
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!) layer.removeAnimationForKey(a.keyPath!)
...@@ -393,12 +393,12 @@ public class MaterialButton : UIButton { ...@@ -393,12 +393,12 @@ public class MaterialButton : UIButton {
let t: CFTimeInterval = 0.25 let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity { if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v) self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
self.pulseLayer.position = point self.pulseLayer.position = point
self.pulseLayer.cornerRadius = r / d self.pulseLayer.cornerRadius = r / d
}) }
pulseLayer.addAnimation(MaterialAnimation.scale(pulseFill ? 3 * d : 1.5 * d, duration: t), forKey: nil) pulseLayer.addAnimation(MaterialAnimation.scale(pulseFill ? 3 * d : 1.5 * d, duration: t), forKey: nil)
} }
...@@ -416,9 +416,9 @@ public class MaterialButton : UIButton { ...@@ -416,9 +416,9 @@ public class MaterialButton : UIButton {
if spotlight { if spotlight {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer) let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if layer.containsPoint(point) { if layer.containsPoint(point) {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.pulseLayer.position = point self.pulseLayer.position = point
}) }
} }
} }
} }
......
...@@ -254,9 +254,9 @@ public class MaterialLayer : CAShapeLayer { ...@@ -254,9 +254,9 @@ public class MaterialLayer : CAShapeLayer {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) self.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}) }
} }
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
removeAnimationForKey(a.keyPath!) removeAnimationForKey(a.keyPath!)
......
...@@ -51,14 +51,14 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -51,14 +51,14 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
private lazy var rightOnDragRelease: Bool = false private lazy var rightOnDragRelease: Bool = false
/** /**
:name: leftLayer :name: leftView
*/ */
public private(set) lazy var leftLayer: MaterialLayer = MaterialLayer() public private(set) lazy var leftView: MaterialView = MaterialView()
/** /**
:name: rightLayer :name: rightView
*/ */
public private(set) lazy var rightLayer: MaterialLayer = MaterialLayer() public private(set) lazy var rightView: MaterialView = MaterialView()
/** /**
:name: revealed :name: revealed
...@@ -66,6 +66,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -66,6 +66,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
public private(set) lazy var revealed: Bool = false public private(set) lazy var revealed: Bool = false
/** /**
:name: closeAutomatically
*/
public lazy var closeAutomatically: Bool = true
/**
:name: gestureRecognizerShouldBegin :name: gestureRecognizerShouldBegin
*/ */
public override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { public override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
...@@ -94,8 +99,8 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -94,8 +99,8 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
borderColor = MaterialTheme.pulseCollectionView.bordercolor borderColor = MaterialTheme.pulseCollectionView.bordercolor
masksToBounds = true masksToBounds = true
prepareLeftLayer() prepareLeftView()
prepareRightLayer() prepareRightView()
preparePanGesture() preparePanGesture()
} }
...@@ -117,20 +122,27 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -117,20 +122,27 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
} }
} }
/**
:name: close
*/
public func close() {
animation(MaterialAnimation.position(CGPointMake(width / 2, y + height / 2), duration: 0.25))
}
// //
// :name: prepareLeftLayer // :name: prepareLeftView
// //
internal func prepareLeftLayer() { internal func prepareLeftView() {
leftLayer.frame = CGRectMake(-width, 0, width, height) leftView.frame = CGRectMake(-width, 0, width, height)
layer.addSublayer(leftLayer) addSubview(leftView)
} }
// //
// :name: prepareRightLayer // :name: prepareRightView
// //
internal func prepareRightLayer() { internal func prepareRightView() {
rightLayer.frame = CGRectMake(width, 0, width, height) rightView.frame = CGRectMake(width, 0, width, height)
layer.addSublayer(rightLayer) addSubview(rightView)
} }
// //
...@@ -150,17 +162,17 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -150,17 +162,17 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case .Began: case .Began:
originalPosition = position originalPosition = position
masksToBounds = false masksToBounds = false
rightOnDragRelease = x < -width / 2
leftOnDragRelease = x > width / 2 leftOnDragRelease = x > width / 2
rightOnDragRelease = x < -width / 2
case .Changed: case .Changed:
let translation = recognizer.translationInView(self) let translation = recognizer.translationInView(self)
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.position.x = self.originalPosition.x + translation.x self.position.x = self.originalPosition.x + translation.x
}) }
rightOnDragRelease = x < -width / 2
leftOnDragRelease = x > width / 2 leftOnDragRelease = x > width / 2
rightOnDragRelease = x < -width / 2
if !revealed && (leftOnDragRelease || rightOnDragRelease) { if !revealed && (leftOnDragRelease || rightOnDragRelease) {
revealed = true revealed = true
...@@ -180,7 +192,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI ...@@ -180,7 +192,11 @@ public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UI
case .Ended: case .Ended:
revealed = false revealed = false
// snap back // snap back
animation(MaterialAnimation.position(CGPointMake(width / 2, y + height / 2), duration: 0.25)) if !leftOnDragRelease || !rightOnDragRelease {
close()
} else if closeAutomatically && (leftOnDragRelease || rightOnDragRelease) {
close()
}
default:break default:break
} }
......
...@@ -385,9 +385,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -385,9 +385,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}) }
} }
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!) layer.removeAnimationForKey(a.keyPath!)
...@@ -411,9 +411,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -411,9 +411,9 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
let t: CFTimeInterval = 0.25 let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity { if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.pulseLayer.bounds = CGRectMake(0, 0, 2 * w, 2 * h) self.pulseLayer.bounds = CGRectMake(0, 0, 2 * w, 2 * h)
}) }
MaterialAnimation.animationWithDuration(t, animations: { MaterialAnimation.animationWithDuration(t, animations: {
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
}) })
......
...@@ -84,12 +84,12 @@ public class MaterialPulseView : MaterialView { ...@@ -84,12 +84,12 @@ public class MaterialPulseView : MaterialView {
let t: CFTimeInterval = 0.25 let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity { if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v) self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
self.pulseLayer.position = point self.pulseLayer.position = point
self.pulseLayer.cornerRadius = r / d self.pulseLayer.cornerRadius = r / d
}) }
pulseLayer.addAnimation(MaterialAnimation.scale(pulseFill ? 3 * d : d, duration: t), forKey: nil) pulseLayer.addAnimation(MaterialAnimation.scale(pulseFill ? 3 * d : d, duration: t), forKey: nil)
} }
...@@ -107,9 +107,9 @@ public class MaterialPulseView : MaterialView { ...@@ -107,9 +107,9 @@ public class MaterialPulseView : MaterialView {
if spotlight { if spotlight {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer) let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if layer.containsPoint(point) { if layer.containsPoint(point) {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.pulseLayer.position = point self.pulseLayer.position = point
}) }
} }
} }
} }
......
...@@ -101,10 +101,10 @@ public class MaterialView : UIView { ...@@ -101,10 +101,10 @@ public class MaterialView : UIView {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return frame.origin.x return layer.frame.origin.x
} }
set(value) { set(value) {
frame.origin.x = value layer.frame.origin.x = value
} }
} }
...@@ -365,9 +365,9 @@ public class MaterialView : UIView { ...@@ -365,9 +365,9 @@ public class MaterialView : UIView {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
}) }
} }
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!) layer.removeAnimationForKey(a.keyPath!)
......
...@@ -39,17 +39,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -39,17 +39,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// //
// :name: originalPosition // :name: originalPosition
// //
private var originalPosition: CGPoint! private lazy var originalPosition: CGPoint = CGPointZero
// //
// :name: leftPanGesture // :name: sidePanGesture
// //
internal var leftPanGesture: UIPanGestureRecognizer? internal var sidePanGesture: UIPanGestureRecognizer?
// //
// :name: leftTapGesture // :name: sideTapGesture
// //
internal var leftTapGesture: UITapGestureRecognizer? internal var sideTapGesture: UITapGestureRecognizer?
// //
// :name: isViewBasedAppearance // :name: isViewBasedAppearance
...@@ -63,10 +63,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -63,10 +63,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
public var userInteractionEnabled: Bool { public var userInteractionEnabled: Bool {
get { get {
return mainViewController!.view.userInteractionEnabled return mainViewController.view.userInteractionEnabled
} }
set(value) { set(value) {
mainViewController!.view.userInteractionEnabled = value mainViewController.view.userInteractionEnabled = value
} }
} }
...@@ -114,31 +114,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -114,31 +114,36 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: isLeftContainerOpened :name: opened
*/ */
public var isLeftContainerOpened: Bool { public var opened: Bool {
return leftView?.x != -leftViewControllerWidth return sideView.position.x == sideViewControllerWidth / 2
} }
/** /**
:name: leftView :name: sideView
*/ */
public private(set) var leftView: MaterialView? public private(set) var sideView: MaterialView = MaterialView()
/** /**
:name: maintViewController :name: maintViewController
*/ */
public var mainViewController: UIViewController? public var mainViewController: UIViewController!
/** /**
:name: leftViewController :name: sideViewController
*/ */
public var leftViewController: UIViewController? public var sideViewController: UIViewController!
/** /**
:name: leftViewControllerWidth :name: sideViewControllerWidth
*/ */
public private(set) var leftViewControllerWidth: CGFloat = 240 public var sideViewControllerWidth: CGFloat = 240 {
didSet {
horizontalThreshold = sideViewControllerWidth / 2
layoutSideView()
}
}
/** /**
:name: init :name: init
...@@ -157,13 +162,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -157,13 +162,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/** /**
:name: init :name: init
*/ */
public convenience init(mainViewController: UIViewController, leftViewController: UIViewController) { public convenience init(mainViewController: UIViewController, sideViewController: UIViewController) {
self.init() self.init()
self.mainViewController = mainViewController self.mainViewController = mainViewController
self.leftViewController = leftViewController self.sideViewController = sideViewController
prepareView() prepareView()
prepareMainView()
prepareLeftView()
} }
// //
...@@ -177,92 +180,56 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -177,92 +180,56 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
layoutBackdropLayer() layoutBackdropLayer()
if let v: MaterialView = leftView { layoutSideView()
leftViewController?.view.frame = v.bounds
leftViewController?.view.center = CGPointMake(v.width / 2, v.height / 2)
}
} }
/** /**
:name: setLeftViewControllerWidth :name: toggleSideViewContainer
*/ */
public func setLeftViewControllerWidth(width: CGFloat, hidden: Bool, animated: Bool) { public func toggleSideViewContainer(velocity: CGFloat = 0) {
leftViewControllerWidth = width opened ? close(velocity) : open(velocity)
let w: CGFloat = (hidden ? -width : width) / 2
if animated {
MaterialAnimation.animationWithDuration(0.25, animations: {
self.leftView!.width = width
self.leftView!.position.x = w
}) {
self.userInteractionEnabled = false
}
} else {
MaterialAnimation.animationDisabled({
self.leftView!.width = width
self.leftView!.position.x = w
})
}
} }
/** /**
:name: toggleLeftViewContainer :name: open
*/ */
public func toggleLeftViewContainer(velocity: CGFloat = 0) { public func open(velocity: CGFloat = 0) {
isLeftContainerOpened ? closeLeftViewContainer(velocity) : openLeftViewContainer(velocity) toggleStatusBar(true)
MaterialAnimation.animationWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(sideView.x / velocity)))),
animations: {
self.sideView.position.x = self.sideViewControllerWidth / 2
self.backdropLayer.hidden = false
}) {
self.userInteractionEnabled = false
}
} }
/** /**
:name: openLeftViewContainer :name: close
*/ */
public func openLeftViewContainer(velocity: CGFloat = 0) { public func close(velocity: CGFloat = 0) {
if let v = leftView { toggleStatusBar(false)
let w: CGFloat = v.width MaterialAnimation.animationWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(sideView.x / velocity)))),
let h: CGFloat = v.height animations: {
let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))) self.sideView.position.x = -self.sideViewControllerWidth / 2
self.backdropLayer.hidden = true
toggleStatusBar(true) }) {
MaterialAnimation.animationWithDuration(d, animations: { self.userInteractionEnabled = true
v.position = CGPointMake(w / 2, h / 2)
self.backdropLayer.hidden = false
}) {
self.userInteractionEnabled = false
}
} }
} }
/** /**
:name: closeLeftViewContainer :name: gestureRecognizer
*/ */
public func closeLeftViewContainer(velocity: CGFloat = 0) {
if let v = leftView {
let w: CGFloat = v.width
let h: CGFloat = v.height
let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity))))
toggleStatusBar(false)
MaterialAnimation.animationWithDuration(d, animations: {
v.position = CGPointMake(-w / 2, h / 2)
self.backdropLayer.hidden = true
}) {
self.userInteractionEnabled = true
}
}
}
//
// :name: gestureRecognizer
//
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool { public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if !enabled { if !enabled {
return false return false
} }
if gestureRecognizer == leftPanGesture { if gestureRecognizer == sidePanGesture {
return gesturePanLeftViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view)) return gesturePanSideViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
} }
if gestureRecognizer == leftTapGesture { if gestureRecognizer == sideTapGesture {
return isLeftContainerOpened && !isPointContainedWithinViewController(leftView!, point: touch.locationInView(view)) return opened && !isPointContainedWithinViewController(sideView, point: touch.locationInView(view))
} }
return false return false
} }
...@@ -273,70 +240,79 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -273,70 +240,79 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
internal func prepareView() { internal func prepareView() {
backdropColor = MaterialColor.black backdropColor = MaterialColor.black
prepareBackdropLayer() prepareBackdropLayer()
prepareMainView()
prepareSideView()
} }
// //
// :name: prepareMainView // :name: prepareMainView
// //
internal func prepareMainView() { internal func prepareMainView() {
prepareViewControllerWithinContainer(mainViewController!, container: view) prepareViewControllerWithinContainer(mainViewController, container: view)
} mainViewController.view.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: mainViewController.view)
// }
// :name: prepareLeftView
// //
internal func prepareLeftView() { // :name: prepareSideView
// container //
leftView = MaterialView(frame: CGRectMake(0, 0, leftViewControllerWidth, view.frame.height)) internal func prepareSideView() {
leftView!.backgroundColor = MaterialColor.clear MaterialAnimation.animationDisabled {
view.addSubview(leftView!) self.sideView.frame = CGRectMake(0, 0, self.sideViewControllerWidth, self.view.bounds.height)
self.sideView.position = CGPointMake(-self.sideViewControllerWidth / 2, self.view.bounds.height / 2)
MaterialAnimation.animationDisabled({ }
self.leftView!.position.x = -self.leftViewControllerWidth / 2 sideView.backgroundColor = MaterialColor.blue.accent3
self.leftView!.zPosition = 1000 sideView.zPosition = 1000
}) view.addSubview(sideView)
prepareViewControllerWithinContainer(leftViewController!, container: leftView!)
// gestures
prepareLeftGestures() prepareLeftGestures()
prepareViewControllerWithinContainer(sideViewController, container: sideView)
} }
// //
// :name: handleLeftPanGesture // :name: layoutSideView
// //
internal func handleLeftPanGesture(recognizer: UIPanGestureRecognizer) { internal func layoutSideView() {
if let v = leftView { MaterialAnimation.animationDisabled {
switch recognizer.state { self.sideView.width = self.sideViewControllerWidth
case .Began: self.sideView.height = self.view.bounds.height
originalPosition = v.position self.sideView.position = CGPointMake((self.opened ? 1 : -1) * self.sideViewControllerWidth / 2, self.view.bounds.height / 2)
toggleStatusBar(true) // self.sideViewController.view.frame = self.sideView.bounds
backdropLayer.hidden = false }
case .Changed: }
let translation: CGPoint = recognizer.translationInView(v)
let w: CGFloat = v.width //
MaterialAnimation.animationDisabled({ // :name: handlePanGesture
v.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x //
}) internal func handlePanGesture(recognizer: UIPanGestureRecognizer) {
case .Ended: switch recognizer.state {
let point: CGPoint = recognizer.velocityInView(recognizer.view) case .Began:
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0 toggleStatusBar(true)
if v.x <= CGFloat(floor(-leftViewControllerWidth)) + horizontalThreshold || point.x <= -1000 { originalPosition = sideView.position
closeLeftViewContainer(x) backdropLayer.hidden = false
} else { case .Changed:
openLeftViewContainer(x) let translation: CGPoint = recognizer.translationInView(view)
} let x: CGFloat = self.sideViewControllerWidth / 2
default:break MaterialAnimation.animationDisabled {
self.sideView.position.x = self.originalPosition.x + translation.x > x ? x : self.originalPosition.x + translation.x
}
case .Ended:
let point: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0
if sideView.x <= CGFloat(floor(-sideViewControllerWidth)) + horizontalThreshold || point.x <= -1000 {
close(x)
} else {
open(x)
} }
default:break
} }
} }
// //
// :name: handleLeftTapGesture // :name: handleTapGesture
// //
internal func handleLeftTapGesture(recognizer: UIPanGestureRecognizer) { internal func handleTapGesture(recognizer: UIPanGestureRecognizer) {
if let _ = leftView { if opened {
closeLeftViewContainer() close()
} }
} }
...@@ -360,12 +336,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -360,12 +336,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: removeGestures // :name: removeGestures
// //
private func removeGestures(inout pan: UIPanGestureRecognizer?, inout tap: UITapGestureRecognizer?) { private func removeGestures(inout pan: UIPanGestureRecognizer?, inout tap: UITapGestureRecognizer?) {
if let g = pan { if let v = pan {
view.removeGestureRecognizer(g) view.removeGestureRecognizer(v)
v.delegate = nil
pan = nil pan = nil
} }
if let g = tap { if let v = tap {
view.removeGestureRecognizer(g) view.removeGestureRecognizer(v)
v.delegate = nil
tap = nil tap = nil
} }
} }
...@@ -397,17 +375,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -397,17 +375,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
// //
// :name: gesturePanLeftViewController // :name: gesturePanSideViewController
// //
private func gesturePanLeftViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool { private func gesturePanSideViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return isLeftContainerOpened || enabled && isLeftPointContainedWithinRect(point) return opened || enabled && isPointContainedWithinHorizontalThreshold(point)
} }
// //
// :name: isLeftPointContainedWithinRect // :name: isPointContainedWithinHorizontalThreshold
// //
private func isLeftPointContainedWithinRect(point: CGPoint) -> Bool { private func isPointContainedWithinHorizontalThreshold(point: CGPoint) -> Bool {
return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.frame.height), point) return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.bounds.height), point)
} }
// //
...@@ -428,18 +406,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -428,18 +406,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: layoutBackdropLayer // :name: layoutBackdropLayer
// //
private func layoutBackdropLayer() { private func layoutBackdropLayer() {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled {
self.backdropLayer.frame = self.view.bounds self.backdropLayer.frame = self.view.bounds
self.backdropLayer.zPosition = 900 self.backdropLayer.zPosition = 900
self.backdropLayer.hidden = true self.backdropLayer.hidden = true
}) }
} }
// //
// :name: prepareViewControllerWithinContainer // :name: prepareViewControllerWithinContainer
// //
private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) { private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) {
controller.view.clipsToBounds = true
addChildViewController(controller) addChildViewController(controller)
container.addSubview(controller.view) container.addSubview(controller.view)
controller.didMoveToParentViewController(self) controller.didMoveToParentViewController(self)
...@@ -449,7 +426,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -449,7 +426,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareLeftGestures // :name: prepareLeftGestures
// //
private func prepareLeftGestures() { private func prepareLeftGestures() {
removeGestures(&leftPanGesture, tap: &leftTapGesture) removeGestures(&sidePanGesture, tap: &sideTapGesture)
prepareGestures(&leftPanGesture, panSelector: "handleLeftPanGesture:", tap: &leftTapGesture, tapSelector: "handleLeftTapGesture:") prepareGestures(&sidePanGesture, panSelector: "handlePanGesture:", tap: &sideTapGesture, tapSelector: "handleTapGesture:")
} }
} }
\ 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