Commit 0b5cc8ce by adamdahan

Refactored Cards to use Base pulse view, Added new image card + Fixed touch…

Refactored Cards to use Base pulse view, Added new image card + Fixed touch handling on Cards to elimated pulse on touchesCancelled
parent 981b12fb
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; }; 9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; };
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; }; 9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; };
9A94D0FD1B895EA500F586A5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */; }; 9A94D0FD1B895EA500F586A5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */; };
9A94D1091B8A3F5100F586A5 /* PulseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A94D1081B8A3F5100F586A5 /* PulseView.swift */; };
9A94D10B1B8A485C00F586A5 /* ImageCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A94D10A1B8A485C00F586A5 /* ImageCard.swift */; };
9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; }; 9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; };
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; }; 9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; };
9AAC385F1B8957A200FE6B2D /* BasicCard.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9AAC385F1B8957A200FE6B2D /* BasicCard.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -63,6 +65,8 @@ ...@@ -63,6 +65,8 @@
963832671B88E5BF0015F710 /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; }; 963832671B88E5BF0015F710 /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; };
963832681B88E5BF0015F710 /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; }; 963832681B88E5BF0015F710 /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
963832871B8908180015F710 /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; }; 963832871B8908180015F710 /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; };
9A94D1081B8A3F5100F586A5 /* PulseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PulseView.swift; sourceTree = "<group>"; };
9A94D10A1B8A485C00F586A5 /* ImageCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCard.swift; sourceTree = "<group>"; };
9AAC384C1B89528900FE6B2D /* BasicCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCard.swift; sourceTree = "<group>"; }; 9AAC384C1B89528900FE6B2D /* BasicCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCard.swift; sourceTree = "<group>"; };
9AAC38531B89559900FE6B2D /* Roboto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Roboto.swift; sourceTree = "<group>"; }; 9AAC38531B89559900FE6B2D /* Roboto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Roboto.swift; sourceTree = "<group>"; };
9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; }; 9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; };
...@@ -110,6 +114,7 @@ ...@@ -110,6 +114,7 @@
963832521B88E30F0015F710 /* Source */ = { 963832521B88E30F0015F710 /* Source */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9A94D1071B8A3F4200F586A5 /* Base */,
963832631B88E5BF0015F710 /* LICENSE */, 963832631B88E5BF0015F710 /* LICENSE */,
9638325C1B88E3420015F710 /* Supporting Files */, 9638325C1B88E3420015F710 /* Supporting Files */,
9AAC38521B89553800FE6B2D /* Font */, 9AAC38521B89553800FE6B2D /* Font */,
...@@ -184,10 +189,19 @@ ...@@ -184,10 +189,19 @@
name = Layout; name = Layout;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
9A94D1071B8A3F4200F586A5 /* Base */ = {
isa = PBXGroup;
children = (
9A94D1081B8A3F5100F586A5 /* PulseView.swift */,
);
name = Base;
sourceTree = "<group>";
};
9AAC384B1B89524E00FE6B2D /* Card */ = { 9AAC384B1B89524E00FE6B2D /* Card */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9AAC384C1B89528900FE6B2D /* BasicCard.swift */, 9AAC384C1B89528900FE6B2D /* BasicCard.swift */,
9A94D10A1B8A485C00F586A5 /* ImageCard.swift */,
); );
name = Card; name = Card;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -325,7 +339,9 @@ ...@@ -325,7 +339,9 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
963832691B88E5BF0015F710 /* Capture.swift in Sources */, 963832691B88E5BF0015F710 /* Capture.swift in Sources */,
9A94D10B1B8A485C00F586A5 /* ImageCard.swift in Sources */,
9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */, 9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */,
9A94D1091B8A3F5100F586A5 /* PulseView.swift in Sources */,
9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */, 9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */,
963832711B88E5BF0015F710 /* Text.swift in Sources */, 963832711B88E5BF0015F710 /* Text.swift in Sources */,
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */, 9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
......
...@@ -19,66 +19,30 @@ ...@@ -19,66 +19,30 @@
import UIKit import UIKit
import QuartzCore import QuartzCore
public class BasicCard : UIView { public class BasicCard : PulseView {
private var views: NSMutableDictionary = NSMutableDictionary()
public var cancelButton: FlatButton = FlatButton() public var cancelButton: FlatButton = FlatButton()
public var otherButton: FlatButton = FlatButton() public var otherButton: FlatButton = FlatButton()
public var color: UIColor?
public var pulseColor: UIColor?
public var titleLabel: UILabel = UILabel() public var titleLabel: UILabel = UILabel()
public var detailTextLabel: UILabel = UILabel() public var detailTextLabel: UILabel = UILabel()
public var horizontalSeparator: UIView = UIView() public var horizontalSeparator: UIView = UIView()
public var backgroundColorView: UIView?
public var pulseView: UIView?
public required init(coder aDecoder: NSCoder) { public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
initialize()
} }
public required override init(frame: CGRect) { public required init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
initialize()
} }
func initialize() { internal override func initialize() {
setupSelf()
setupLayer()
setupTitleLabel() setupTitleLabel()
setupDetailTextLabel() setupDetailTextLabel()
setupHorizontalLineSeparator() setupHorizontalLineSeparator()
setupButtons() setupButtons()
setupBackgroundColorView() super.initialize()
constrainSubviews()
}
func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillRect(context, rect)
CGContextRestoreGState(context)
}
func setupSelf() {
color = UIColor.clearColor()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColor = UIColor(red: 66.0/255.0, green: 91.0/255.0, blue: 103.0/255.0, alpha: 1.0)
}
func setupLayer() {
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOffset = CGSizeMake(0.5, 0.5)
self.layer.shadowRadius = 5.0
self.layer.shadowOpacity = 0.4
self.layer.cornerRadius = 2.0
} }
func setupTitleLabel() { func setupTitleLabel() {
...@@ -86,7 +50,7 @@ public class BasicCard : UIView { ...@@ -86,7 +50,7 @@ public class BasicCard : UIView {
titleLabel.font = Roboto.regularWithSize(22.0) titleLabel.font = Roboto.regularWithSize(22.0)
titleLabel.textColor = UIColor.whiteColor() titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title" titleLabel.text = "Card Title"
self.addSubview(titleLabel) addSubview(titleLabel)
views.setObject(titleLabel, forKey: "titleLabel") views.setObject(titleLabel, forKey: "titleLabel")
} }
...@@ -134,24 +98,8 @@ public class BasicCard : UIView { ...@@ -134,24 +98,8 @@ public class BasicCard : UIView {
views.setObject(otherButton, forKey: "otherButton") views.setObject(otherButton, forKey: "otherButton")
} }
// We need this view so we can use the masksToBounds internal override func constrainSubviews() {
// so the pulse doesn't animate off the button super.constrainSubviews()
func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView!.layer.cornerRadius = 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
self.insertSubview(backgroundColorView!, atIndex: 0)
views.setObject(backgroundColorView!, forKey: "bgView")
}
func constrainSubviews() {
// Background
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
// Title & Detail Text Label // Title & Detail Text Label
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject])) addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject])) addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
...@@ -166,45 +114,4 @@ public class BasicCard : UIView { ...@@ -166,45 +114,4 @@ public class BasicCard : UIView {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject])) addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
} }
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView?.setTranslatesAutoresizingMaskIntoConstraints(false)
var width = bounds.size.width / 3.0
pulseView!.frame = CGRectMake(0, 0, width, width)
pulseView!.layer.cornerRadius = width / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.1)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, completion: nil)
}
func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
}
func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
} }
...@@ -119,6 +119,11 @@ public class FabButton : UIButton { ...@@ -119,6 +119,11 @@ public class FabButton : UIButton {
removePulse() removePulse()
} }
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) { func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
......
...@@ -84,6 +84,11 @@ public class FlatButton : UIButton { ...@@ -84,6 +84,11 @@ public class FlatButton : UIButton {
removePulse() removePulse()
} }
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) { func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
......
//
// ImageCard.swift
// MaterialKit
//
// Created by Adam Dahan on 2015-08-23.
// Copyright (c) 2015 GraphKit Inc. All rights reserved.
//
import UIKit
public class ImageCard : PulseView {
public lazy var imageView: UIImageView = UIImageView()
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public required init(frame: CGRect) {
super.init(frame: frame)
}
internal override func initialize() {
setupImageView()
super.initialize()
}
func setupImageView() {
imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
imageView.contentMode = .ScaleAspectFill
imageView.userInteractionEnabled = false
imageView.clipsToBounds = true
addSubview(imageView)
views.setObject(imageView, forKey: "imageView")
}
internal override func constrainSubviews() {
super.constrainSubviews()
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[imageView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[imageView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
}
}
//
// PulseView.swift
// MaterialKit
//
// Created by Adam Dahan on 2015-08-23.
// Copyright (c) 2015 GraphKit Inc. All rights reserved.
//
import UIKit
public class PulseView : UIView {
internal lazy var views: NSMutableDictionary = NSMutableDictionary()
public var backgroundColorView: UIView?
public var pulseView: UIView?
public var color: UIColor?
public var pulseColor: UIColor?
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
internal func initialize() {
setupSelf()
setupLayer()
setupBackgroundColorView()
constrainSubviews()
}
private func setupSelf() {
color = UIColor.clearColor()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColor = UIColor(red: 66.0/255.0, green: 91.0/255.0, blue: 103.0/255.0, alpha: 1.0)
}
private func setupLayer() {
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSizeMake(0.5, 0.5)
layer.shadowRadius = 5.0
layer.shadowOpacity = 0.4
layer.cornerRadius = 2.0
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView?.userInteractionEnabled = false
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView!.layer.cornerRadius = 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
addSubview(backgroundColorView!)
views.setObject(backgroundColorView!, forKey: "bgView")
}
internal func constrainSubviews() {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView?.setTranslatesAutoresizingMaskIntoConstraints(false)
var width = bounds.size.width / 3.0
pulseView!.frame = CGRectMake(0, 0, width, width)
pulseView!.layer.cornerRadius = width / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.1)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, completion: nil)
}
func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
}
func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
}
...@@ -85,6 +85,11 @@ public class RaisedButton : UIButton { ...@@ -85,6 +85,11 @@ public class RaisedButton : UIButton {
removePulse() removePulse()
} }
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) { func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
......
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