Commit 4e2e0f24 by danieldahan

updated to latest

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