Commit 1a298e0f by Daniel Dahan

updating internal layout updates

parent d20bca54
...@@ -67,7 +67,7 @@ public class MaterialButton : UIButton { ...@@ -67,7 +67,7 @@ public class MaterialButton : UIButton {
*/ */
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity { public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet { didSet {
preparePulseLayer() updatePulseLayer()
} }
} }
...@@ -76,7 +76,7 @@ public class MaterialButton : UIButton { ...@@ -76,7 +76,7 @@ public class MaterialButton : UIButton {
*/ */
public var pulseColor: UIColor? { public var pulseColor: UIColor? {
didSet { didSet {
preparePulseLayer() updatePulseLayer()
} }
} }
...@@ -302,6 +302,7 @@ public class MaterialButton : UIButton { ...@@ -302,6 +302,7 @@ public class MaterialButton : UIButton {
shape = .None shape = .None
contentInsets = .None contentInsets = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -449,15 +450,26 @@ public class MaterialButton : UIButton { ...@@ -449,15 +450,26 @@ public class MaterialButton : UIButton {
:name: prepareView :name: prepareView
*/ */
public func prepareView() { public func prepareView() {
// visualLayer prepareVisualLayer()
preparePulseLayer()
}
//
// :name: prepareVisualLayer
//
internal func prepareVisualLayer() {
visualLayer.zPosition = -1 visualLayer.zPosition = -1
visualLayer.masksToBounds = true visualLayer.masksToBounds = true
layer.addSublayer(visualLayer) layer.addSublayer(visualLayer)
}
// pulseLayer
pulseLayer.hidden = true //
pulseLayer.zPosition = 1 // :name: layoutVisualLayer
visualLayer.addSublayer(pulseLayer) //
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
} }
// //
...@@ -470,18 +482,18 @@ public class MaterialButton : UIButton { ...@@ -470,18 +482,18 @@ public class MaterialButton : UIButton {
} }
// //
// :name: layoutVisualLayer // :name: preparePulseLayer
// //
internal func layoutVisualLayer() { internal func preparePulseLayer() {
visualLayer.frame = bounds pulseLayer.hidden = true
visualLayer.position = CGPointMake(width / 2, height / 2) pulseLayer.zPosition = 1
visualLayer.cornerRadius = layer.cornerRadius visualLayer.addSublayer(pulseLayer)
} }
// //
// :name: preparePulseLayer // :name: updatePulseLayer
// //
internal func preparePulseLayer() { internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
} }
......
...@@ -80,7 +80,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -80,7 +80,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
*/ */
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity { public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet { didSet {
preparePulseLayer() updatePulseLayer()
} }
} }
...@@ -89,7 +89,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -89,7 +89,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
*/ */
public var pulseColor: UIColor? { public var pulseColor: UIColor? {
didSet { didSet {
preparePulseLayer() updatePulseLayer()
} }
} }
...@@ -304,6 +304,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -304,6 +304,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
shadowDepth = .None shadowDepth = .None
shape = .None shape = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -325,15 +326,14 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -325,15 +326,14 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
} }
/** /**
:name: layoutSubviews :name: layoutSublayersOfLayer
*/ */
public override func layoutSubviews() { public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSubviews() super.layoutSublayersOfLayer(layer)
layoutShape() if self.layer == layer {
layoutShape()
visualLayer.frame = bounds layoutVisualLayer()
visualLayer.position = CGPointMake(width / 2, height / 2) }
visualLayer.cornerRadius = layer.cornerRadius
} }
/** /**
...@@ -457,21 +457,64 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -457,21 +457,64 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
borderColor = MaterialTheme.flatButton.bordercolor borderColor = MaterialTheme.flatButton.bordercolor
shape = MaterialTheme.flatButton.shape shape = MaterialTheme.flatButton.shape
// visualLayer prepareVisualLayer()
preparePulseLayer()
preparePanGesture()
}
//
// :name: prepareVisualLayer
//
internal func prepareVisualLayer() {
visualLayer.zPosition = -1 visualLayer.zPosition = -1
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer) layer.addSublayer(visualLayer)
}
// pulseLayer
//
// :name: layoutVisualLayer
//
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
//
// :name: layoutShape
//
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
//
// :name: preparePulseLayer
//
internal func preparePulseLayer() {
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.zPosition = 1 pulseLayer.zPosition = 1
visualLayer.addSublayer(pulseLayer) visualLayer.addSublayer(pulseLayer)
}
// gesture
//
// :name: updatePulseLayer
//
internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
//
// :name: preparePanGesture
//
internal func preparePanGesture() {
panRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanGesture:") panRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
panRecognizer.delegate = self panRecognizer.delegate = self
addGestureRecognizer(panRecognizer) addGestureRecognizer(panRecognizer)
} }
// //
// :name: handlePanGesture // :name: handlePanGesture
// //
...@@ -526,31 +569,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni ...@@ -526,31 +569,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
} }
// //
// :name: layoutShape
//
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 2
}
}
//
// :name: layoutVisualLayer
//
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
//
// :name: preparePulseLayer
//
internal func preparePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
//
// :name: shrink // :name: shrink
// //
internal func shrink() { internal func shrink() {
......
...@@ -56,7 +56,7 @@ public class MaterialPulseView : MaterialView { ...@@ -56,7 +56,7 @@ public class MaterialPulseView : MaterialView {
*/ */
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity { public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet { didSet {
preparePulseLayer() updatedPulseLayer()
} }
} }
...@@ -65,7 +65,7 @@ public class MaterialPulseView : MaterialView { ...@@ -65,7 +65,7 @@ public class MaterialPulseView : MaterialView {
*/ */
public var pulseColor: UIColor? { public var pulseColor: UIColor? {
didSet { didSet {
preparePulseLayer() updatedPulseLayer()
} }
} }
...@@ -156,16 +156,22 @@ public class MaterialPulseView : MaterialView { ...@@ -156,16 +156,22 @@ public class MaterialPulseView : MaterialView {
borderWidth = MaterialTheme.pulseView.borderWidth borderWidth = MaterialTheme.pulseView.borderWidth
borderColor = MaterialTheme.pulseView.bordercolor borderColor = MaterialTheme.pulseView.bordercolor
// pulseLayer preparePulseLayer()
}
//
// :name: preparePulseLayer
//
internal func preparePulseLayer() {
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.zPosition = 1 pulseLayer.zPosition = 1
visualLayer.addSublayer(pulseLayer) visualLayer.addSublayer(pulseLayer)
} }
// //
// :name: preparePulseLayer // :name: updatedPulseLayer
// //
internal func preparePulseLayer() { internal func updatedPulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
} }
......
...@@ -291,6 +291,7 @@ public class MaterialView : UIView { ...@@ -291,6 +291,7 @@ public class MaterialView : UIView {
shape = .None shape = .None
cornerRadius = .None cornerRadius = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
} }
/** /**
...@@ -390,19 +391,16 @@ public class MaterialView : UIView { ...@@ -390,19 +391,16 @@ public class MaterialView : UIView {
zPosition = MaterialTheme.view.zPosition zPosition = MaterialTheme.view.zPosition
borderColor = MaterialTheme.view.bordercolor borderColor = MaterialTheme.view.bordercolor
// visualLayer prepareVisualLayer()
visualLayer.zPosition = -1
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
} }
// //
// :name: layoutShape // :name: prepareVisualLayer
// //
internal func layoutShape() { internal func prepareVisualLayer() {
if .Circle == shape { visualLayer.zPosition = -1
layer.cornerRadius = width / 2 visualLayer.masksToBounds = true
} layer.addSublayer(visualLayer)
} }
// //
...@@ -413,4 +411,13 @@ public class MaterialView : UIView { ...@@ -413,4 +411,13 @@ public class MaterialView : UIView {
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = layer.cornerRadius
} }
//
// :name: layoutShape
//
internal func layoutShape() {
if .Circle == shape {
layer.cornerRadius = width / 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