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!)
......
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