Commit c7ffe7a3 by Daniel Dahan

added MaterialPulseCollectionViewCell and MaterialPanCollectionViewCell

parent 1a298e0f
......@@ -69,6 +69,7 @@
9693BF991BCDC1450087054A /* SideNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF981BCDC1450087054A /* SideNavigationViewController.swift */; settings = {ASSET_TAGS = (); }; };
9693BF9C1BCDC16C0087054A /* MaterialCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF9B1BCDC16C0087054A /* MaterialCollectionViewCell.swift */; settings = {ASSET_TAGS = (); }; };
9693BF9E1BCDC1840087054A /* BasicCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF9D1BCDC1840087054A /* BasicCollectionViewCell.swift */; settings = {ASSET_TAGS = (); }; };
9693BFA01BCF36A40087054A /* MaterialPulseCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF9F1BCF36A40087054A /* MaterialPulseCollectionViewCell.swift */; settings = {ASSET_TAGS = (); }; };
9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ASSET_TAGS = (); }; };
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; settings = {ASSET_TAGS = (); }; };
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ASSET_TAGS = (); }; };
......@@ -126,6 +127,7 @@
9693BF981BCDC1450087054A /* SideNavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideNavigationViewController.swift; sourceTree = "<group>"; };
9693BF9B1BCDC16C0087054A /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; };
9693BF9D1BCDC1840087054A /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; };
9693BF9F1BCF36A40087054A /* MaterialPulseCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseCollectionViewCell.swift; sourceTree = "<group>"; };
9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; };
96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; };
96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; };
......@@ -315,6 +317,7 @@
9693BF9A1BCDC15C0087054A /* Collection */ = {
isa = PBXGroup;
children = (
9693BF9F1BCF36A40087054A /* MaterialPulseCollectionViewCell.swift */,
9693BF9B1BCDC16C0087054A /* MaterialCollectionViewCell.swift */,
9693BF9D1BCDC1840087054A /* BasicCollectionViewCell.swift */,
);
......@@ -515,6 +518,7 @@
65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */,
65BDD15B1BB7095E006F7F2B /* MaterialRadius.swift in Sources */,
65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */,
9693BFA01BCF36A40087054A /* MaterialPulseCollectionViewCell.swift in Sources */,
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */,
9693BF861BCB0E0A0087054A /* Material+UIFont.swift in Sources */,
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */,
......
......@@ -18,7 +18,7 @@
import UIKit
public class BasicCollectionViewCell : MaterialCollectionViewCell {
public class BasicCollectionViewCell : MaterialPanCollectionViewCell {
/**
:name: titleLayer
*/
......@@ -30,16 +30,6 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
public private(set) lazy var detailLayer: MaterialTextLayer = MaterialTextLayer()
/**
:name: leftLayer
*/
public private(set) lazy var leftLayer: MaterialLayer = MaterialLayer()
/**
:name: rightLayer
*/
public private(set) lazy var rightLayer: MaterialLayer = MaterialLayer()
/**
:name: prepareView
*/
public override func prepareView() {
......@@ -50,13 +40,5 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
// detail
layer.addSublayer(detailLayer)
// left
leftLayer.frame = CGRectMake(-width, 0, width, height)
layer.addSublayer(leftLayer)
// right
rightLayer.frame = CGRectMake(width, 0, width, height)
layer.addSublayer(rightLayer)
}
}
\ No newline at end of file
......@@ -81,6 +81,18 @@ public class MaterialButton : UIButton {
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
......@@ -201,18 +213,6 @@ public class MaterialButton : UIButton {
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/**
:name: cornerRadius
*/
public var cornerRadius: MaterialRadius? {
......
......@@ -18,18 +18,18 @@
import UIKit
@objc(MaterialCollectionViewCellDelegate)
public protocol MaterialCollectionViewCellDelegate : MaterialDelegate {
optional func materialCollectionViewCellWillPassThresholdForLeftLayer(cell: MaterialCollectionViewCell)
optional func materialCollectionViewCellWillPassThresholdForRightLayer(cell: MaterialCollectionViewCell)
optional func materialCollectionViewCellDidRevealLeftLayer(cell: MaterialCollectionViewCell)
optional func materialCollectionViewCellDidRevealRightLayer(cell: MaterialCollectionViewCell)
optional func materialCollectionViewCellDidCloseLeftLayer(cell: MaterialCollectionViewCell)
optional func materialCollectionViewCellDidCloseRightLayer(cell: MaterialCollectionViewCell)
@objc(MaterialPanCollectionViewCellDelegate)
public protocol MaterialPanCollectionViewCellDelegate : MaterialDelegate {
optional func materialCollectionViewCellWillPassThresholdForLeftLayer(cell: MaterialPanCollectionViewCell)
optional func materialCollectionViewCellWillPassThresholdForRightLayer(cell: MaterialPanCollectionViewCell)
optional func materialCollectionViewCellDidRevealLeftLayer(cell: MaterialPanCollectionViewCell)
optional func materialCollectionViewCellDidRevealRightLayer(cell: MaterialPanCollectionViewCell)
optional func materialCollectionViewCellDidCloseLeftLayer(cell: MaterialPanCollectionViewCell)
optional func materialCollectionViewCellDidCloseRightLayer(cell: MaterialPanCollectionViewCell)
}
@objc(MaterialCollectionViewCell)
public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecognizerDelegate {
@objc(MaterialPanCollectionViewCell)
public class MaterialPanCollectionViewCell : MaterialPulseCollectionViewCell, UIGestureRecognizerDelegate {
//
// :name: panRecognizer
//
......@@ -38,12 +38,12 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
//
// :name: leftOnDragRelease
//
private var leftOnDragRelease: Bool = false
private lazy var leftOnDragRelease: Bool = false
//
// :name: rightOnDragRelease
//
private var rightOnDragRelease: Bool = false
private lazy var rightOnDragRelease: Bool = false
//
// :name: originalPosition
......@@ -51,14 +51,14 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
private var originalPosition: CGPoint!
/**
:name: visualLayer
:name: leftLayer
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
public private(set) lazy var leftLayer: MaterialLayer = MaterialLayer()
/**
:name: pulseLayer
:name: rightLayer
*/
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
public private(set) lazy var rightLayer: MaterialLayer = MaterialLayer()
/**
:name: revealed
......@@ -66,256 +66,17 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
public private(set) lazy var revealed: Bool = false
/**
:name: delegate
*/
public weak var delegate: MaterialCollectionViewCellDelegate?
/**
:name: pulseScale
*/
public lazy var pulseScale: Bool = true
/**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet {
updatePulseLayer()
}
}
/**
:name: pulseColor
*/
public var pulseColor: UIColor? {
didSet {
updatePulseLayer()
}
}
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/**
:name: x
*/
public var x: CGFloat {
get {
return frame.origin.x
}
set(value) {
frame.origin.x = value
}
}
/**
:name: y
*/
public var y: CGFloat {
get {
return frame.origin.y
}
set(value) {
frame.origin.y = value
}
}
/**
:name: width
*/
public var width: CGFloat {
get {
return frame.size.width
}
set(value) {
frame.size.width = value
if .None != shape {
frame.size.height = value
}
}
}
/**
:name: height
*/
public var height: CGFloat {
get {
return frame.size.height
}
set(value) {
frame.size.height = value
if .None != shape {
frame.size.width = value
}
}
}
/**
:name: shadowColor
*/
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: cornerRadius
*/
public var cornerRadius: MaterialRadius? {
didSet {
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
/**
:name: shape
*/
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
frame.size.width = height
} else {
frame.size.height = width
}
}
}
}
/**
:name: borderWidth
*/
public var borderWidth: MaterialBorder {
didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth)
}
}
/**
:name: borderColor
*/
public var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
/**
:name: shadowDepth
*/
public var shadowDepth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
:name: position
*/
public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/**
:name: zPosition
*/
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
borderWidth = .None
shadowDepth = .None
shape = .None
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public override init(frame: CGRect) {
borderWidth = .None
shadowDepth = .None
shape = .None
super.init(frame: frame)
prepareView()
}
/**
......@@ -326,112 +87,8 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
}
/**
:name: layoutSublayersOfLayer
*/
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutShape()
layoutVisualLayer()
}
}
/**
:name: animation
:name: gestureRecognizerShouldBegin
*/
public func animation(animation: CAAnimation) {
animation.delegate = self
if let a: CABasicAnimation = animation as? CABasicAnimation {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
/**
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
*/
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({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) {
let w: CGFloat = width
let h: CGFloat = height
let r: CGFloat = 1.05
let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationDisabled({
self.pulseLayer.bounds = CGRectMake(0, 0, 2 * w, 2 * h)
})
MaterialAnimation.animationWithDuration(t, animations: {
self.pulseLayer.hidden = false
})
}
if pulseScale {
layer.addAnimation(MaterialAnimation.scale(r, duration: t), forKey: nil)
}
}
}
/**
:name: touchesMoved
*/
public override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
}
/**
:name: touchesEnded
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
shrink()
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
shrink()
}
//
// :name: gestureRecognizerShouldBegin
//
public override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
let translation = panGestureRecognizer.translationInView(superview!)
......@@ -443,7 +100,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
/**
:name: prepareView
*/
public func prepareView() {
public override func prepareView() {
userInteractionEnabled = MaterialTheme.flatButton.userInteractionEnabled
backgroundColor = MaterialTheme.flatButton.backgroundColor
pulseColorOpacity = MaterialTheme.flatButton.pulseColorOpacity
......@@ -459,50 +116,25 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
prepareVisualLayer()
preparePulseLayer()
prepareLeftLayer()
prepareRightLayer()
preparePanGesture()
}
//
// :name: prepareVisualLayer
// :name: prepareLeftLayer
//
internal func prepareVisualLayer() {
visualLayer.zPosition = -1
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
internal func prepareLeftLayer() {
leftLayer.frame = CGRectMake(-width, 0, width, height)
layer.addSublayer(leftLayer)
}
//
// :name: layoutVisualLayer
// :name: prepareRightLayer
//
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.zPosition = 1
visualLayer.addSublayer(pulseLayer)
}
//
// :name: updatePulseLayer
//
internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
internal func prepareRightLayer() {
rightLayer.frame = CGRectMake(width, 0, width, height)
layer.addSublayer(rightLayer)
}
//
......@@ -538,16 +170,16 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
if !revealed && (leftOnDragRelease || rightOnDragRelease) {
revealed = true
if leftOnDragRelease {
delegate?.materialCollectionViewCellWillPassThresholdForLeftLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellWillPassThresholdForLeftLayer?(self)
} else if rightOnDragRelease {
delegate?.materialCollectionViewCellWillPassThresholdForRightLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellWillPassThresholdForRightLayer?(self)
}
}
if leftOnDragRelease {
delegate?.materialCollectionViewCellDidRevealLeftLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellDidRevealLeftLayer?(self)
} else if rightOnDragRelease {
delegate?.materialCollectionViewCellDidRevealRightLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellDidRevealRightLayer?(self)
}
case .Ended:
......@@ -559,29 +191,12 @@ public class MaterialCollectionViewCell : UICollectionViewCell, UIGestureRecogni
animation(a)
if leftOnDragRelease {
delegate?.materialCollectionViewCellDidCloseLeftLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellDidCloseLeftLayer?(self)
} else if rightOnDragRelease {
delegate?.materialCollectionViewCellDidCloseRightLayer?(self)
(delegate as? MaterialPanCollectionViewCellDelegate)?.materialCollectionViewCellDidCloseRightLayer?(self)
}
default:break
}
}
//
// :name: shrink
//
internal func shrink() {
let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationWithDuration(t, animations: {
self.pulseLayer.hidden = true
})
}
if pulseScale {
layer.addAnimation(MaterialAnimation.scale(1, duration: t), forKey: nil)
}
}
}
\ No newline at end of file
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class MaterialPulseCollectionViewCell : UICollectionViewCell {
/**
:name: visualLayer
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
:name: pulseLayer
*/
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/**
:name: delegate
*/
public weak var delegate: MaterialDelegate?
/**
:name: pulseScale
*/
public lazy var pulseScale: Bool = true
/**
:name: spotlight
*/
public var spotlight: Bool = false {
didSet {
if spotlight {
pulseFill = false
}
}
}
/**
:name: pulseFill
*/
public var pulseFill: Bool = false {
didSet {
if pulseFill {
spotlight = false
}
}
}
/**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat = MaterialTheme.pulseView.pulseColorOpacity {
didSet {
updatePulseLayer()
}
}
/**
:name: pulseColor
*/
public var pulseColor: UIColor? {
didSet {
updatePulseLayer()
}
}
/**
:name: image
*/
public var image: UIImage? {
didSet {
visualLayer.contents = image?.CGImage
}
}
/**
:name: contentsRect
*/
public var contentsRect: CGRect {
didSet {
visualLayer.contentsRect = contentsRect
}
}
/**
:name: contentsCenter
*/
public var contentsCenter: CGRect {
didSet {
visualLayer.contentsCenter = contentsCenter
}
}
/**
:name: contentsScale
*/
public var contentsScale: CGFloat {
didSet {
visualLayer.contentsScale = contentsScale
}
}
/**
:name: contentsGravity
*/
public var contentsGravity: MaterialGravity {
didSet {
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity)
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
}
}
/**
:name: x
*/
public var x: CGFloat {
get {
return frame.origin.x
}
set(value) {
frame.origin.x = value
}
}
/**
:name: y
*/
public var y: CGFloat {
get {
return frame.origin.y
}
set(value) {
frame.origin.y = value
}
}
/**
:name: width
*/
public var width: CGFloat {
get {
return frame.size.width
}
set(value) {
frame.size.width = value
if .None != shape {
frame.size.height = value
}
}
}
/**
:name: height
*/
public var height: CGFloat {
get {
return frame.size.height
}
set(value) {
frame.size.height = value
if .None != shape {
frame.size.width = value
}
}
}
/**
:name: shadowColor
*/
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/**
:name: shadowDepth
*/
public var shadowDepth: MaterialDepth {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(shadowDepth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
:name: cornerRadius
*/
public var cornerRadius: MaterialRadius? {
didSet {
if let v: MaterialRadius = cornerRadius {
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
}
}
/**
:name: shape
*/
public var shape: MaterialShape {
didSet {
if .None != shape {
if width < height {
frame.size.width = height
} else {
frame.size.height = width
}
}
}
}
/**
:name: borderWidth
*/
public var borderWidth: MaterialBorder {
didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth)
}
}
/**
:name: borderColor
*/
public var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.CGColor
}
}
/**
:name: position
*/
public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/**
:name: zPosition
*/
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
contentsRect = MaterialTheme.pulseCollectionView.contentsRect
contentsCenter = MaterialTheme.pulseCollectionView.contentsCenter
contentsScale = MaterialTheme.pulseCollectionView.contentsScale
contentsGravity = MaterialTheme.pulseCollectionView.contentsGravity
borderWidth = MaterialTheme.pulseCollectionView.borderWidth
shadowDepth = MaterialTheme.pulseCollectionView.shadowDepth
shape = .None
cornerRadius = .None
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public override init(frame: CGRect) {
contentsRect = MaterialTheme.pulseCollectionView.contentsRect
contentsCenter = MaterialTheme.pulseCollectionView.contentsCenter
contentsScale = MaterialTheme.pulseCollectionView.contentsScale
contentsGravity = MaterialTheme.pulseCollectionView.contentsGravity
borderWidth = MaterialTheme.pulseCollectionView.borderWidth
shadowDepth = MaterialTheme.pulseCollectionView.shadowDepth
shape = .None
cornerRadius = .None
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectNull)
}
/**
:name: layoutSublayersOfLayer
*/
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
if self.layer == layer {
layoutShape()
layoutVisualLayer()
}
}
/**
:name: animation
*/
public func animation(animation: CAAnimation) {
animation.delegate = self
if let a: CABasicAnimation = animation as? CABasicAnimation {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
/**
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
*/
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({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) {
let s: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3
let v: CGFloat = s / f
let d: CGFloat = 2 * f
let r: CGFloat = 1.05
let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
self.pulseLayer.position = point
self.pulseLayer.cornerRadius = s / d
})
pulseLayer.addAnimation(MaterialAnimation.scale(pulseFill ? 3 * d : d, duration: t), forKey: nil)
}
if pulseScale {
layer.addAnimation(MaterialAnimation.scale(r, duration: t), forKey: nil)
}
}
}
/**
:name: touchesMoved
*/
public override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
if spotlight {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) {
MaterialAnimation.animationDisabled({
self.pulseLayer.position = point
})
}
}
}
/**
:name: touchesEnded
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
shrink()
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
shrink()
}
/**
:name: prepareView
*/
public func prepareView() {
userInteractionEnabled = MaterialTheme.flatButton.userInteractionEnabled
backgroundColor = MaterialTheme.flatButton.backgroundColor
shadowColor = MaterialTheme.flatButton.shadowColor
zPosition = MaterialTheme.flatButton.zPosition
borderColor = MaterialTheme.flatButton.bordercolor
prepareVisualLayer()
preparePulseLayer()
}
//
// :name: prepareVisualLayer
//
internal func prepareVisualLayer() {
visualLayer.zPosition = -1
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
}
//
// :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.zPosition = 1
visualLayer.addSublayer(pulseLayer)
}
//
// :name: updatePulseLayer
//
internal func updatePulseLayer() {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity).CGColor
}
//
// :name: shrink
//
internal func shrink() {
let t: CFTimeInterval = 0.25
if nil != pulseColor && 0 < pulseColorOpacity {
MaterialAnimation.animationWithDuration(t, animations: {
self.pulseLayer.hidden = true
})
pulseLayer.addAnimation(MaterialAnimation.scale(1, duration: t), forKey: nil)
}
if pulseScale {
layer.addAnimation(MaterialAnimation.scale(1, duration: t), forKey: nil)
}
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ public struct MaterialTheme {
public struct basicCardView {}
public struct imageCardView {}
public struct navigationBarView {}
public struct pulseCollectionView {}
public struct textLayer {}
public struct label {}
public struct flatButton {}
......@@ -204,6 +205,32 @@ public extension MaterialTheme.navigationBarView {
public static var zPosition: CGFloat = 100
}
// pulseCollectionView
public extension MaterialTheme.pulseCollectionView {
// shadow
public static var shadowDepth: MaterialDepth = .None
public static var shadowColor: UIColor = MaterialColor.black
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.white
// interaction
public static var userInteractionEnabled: Bool = true
// image
public static var contentsRect: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsCenter: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsScale: CGFloat = UIScreen.mainScreen().scale
public static var contentsGravity: MaterialGravity = .ResizeAspectFill
// position
public static var zPosition: CGFloat = 0
}
// textLayer
public extension MaterialTheme.textLayer {
// scale
......
......@@ -287,7 +287,7 @@ public class MaterialView : UIView {
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None
shadowDepth = MaterialTheme.view.shadowDepth
shape = .None
cornerRadius = .None
super.init(coder: aDecoder)
......@@ -303,7 +303,7 @@ public class MaterialView : UIView {
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity
borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None
shadowDepth = MaterialTheme.view.shadowDepth
shape = .None
cornerRadius = .None
super.init(frame: frame)
......@@ -386,7 +386,6 @@ public class MaterialView : UIView {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroundColor
shadowDepth = MaterialTheme.view.shadowDepth
shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition
borderColor = MaterialTheme.view.bordercolor
......
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