Commit 62eb6c6d by Daniel Dahan

Merge pull request #14 from GraphKit/development

Development
parents 493444cf 1e46d9c1
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
963832851B89070E0015F710 /* CapturePreview.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9638325F1B88E5BF0015F710 /* CapturePreview.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 963832851B89070E0015F710 /* CapturePreview.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9638325F1B88E5BF0015F710 /* CapturePreview.swift */; settings = {ATTRIBUTES = (Public, ); }; };
963832881B8908180015F710 /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; }; 963832881B8908180015F710 /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; };
963832891B89097D0015F710 /* Layout.swift in Headers */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 963832891B89097D0015F710 /* Layout.swift in Headers */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9638329E1B8EC34D0015F710 /* AddFabButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638329D1B8EC34D0015F710 /* AddFabButton.swift */; };
9A94D0F91B895C8C00F586A5 /* Roboto.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9A94D0F91B895C8C00F586A5 /* Roboto.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; }; 9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; };
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 */; };
...@@ -73,6 +74,7 @@ ...@@ -73,6 +74,7 @@
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>"; };
9638329D1B8EC34D0015F710 /* AddFabButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddFabButton.swift; sourceTree = "<group>"; };
9A94D1081B8A3F5100F586A5 /* MaterialPulseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseView.swift; sourceTree = "<group>"; }; 9A94D1081B8A3F5100F586A5 /* MaterialPulseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseView.swift; sourceTree = "<group>"; };
9A94D10A1B8A485C00F586A5 /* ImageCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCard.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>"; };
...@@ -193,6 +195,7 @@ ...@@ -193,6 +195,7 @@
children = ( children = (
65B9657D1B8A7C330055B139 /* MaterialButton.swift */, 65B9657D1B8A7C330055B139 /* MaterialButton.swift */,
963832601B88E5BF0015F710 /* FabButton.swift */, 963832601B88E5BF0015F710 /* FabButton.swift */,
9638329D1B8EC34D0015F710 /* AddFabButton.swift */,
963832611B88E5BF0015F710 /* FlatButton.swift */, 963832611B88E5BF0015F710 /* FlatButton.swift */,
963832651B88E5BF0015F710 /* RaisedButton.swift */, 963832651B88E5BF0015F710 /* RaisedButton.swift */,
); );
...@@ -367,6 +370,7 @@ ...@@ -367,6 +370,7 @@
65B965751B8A60A00055B139 /* MaterialView.swift in Sources */, 65B965751B8A60A00055B139 /* MaterialView.swift in Sources */,
963832711B88E5BF0015F710 /* Text.swift in Sources */, 963832711B88E5BF0015F710 /* Text.swift in Sources */,
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */, 9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
9638329E1B8EC34D0015F710 /* AddFabButton.swift in Sources */,
65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */, 65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */,
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */, 9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */,
65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */, 65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */,
......
//
// 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 AddFabButton : FabButton {
private var verticalLine: UIView!
private var horizontalLine: UIView!
//
// :name: prepareButton
//
public override func prepareButton() {
super.prepareButton()
prepareVerticalLine()
prepareHorizontalLine()
}
//
// :name: prepareVerticalLine
//
private func prepareVerticalLine() {
verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView.frame) / 3))
verticalLine.backgroundColor = .whiteColor()
verticalLine.center = backgroundColorView.center
backgroundColorView.addSubview(verticalLine)
}
//
// :name: prepareHorizontalLine
//
private func prepareHorizontalLine() {
horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView.frame) / 3, lineWidth))
horizontalLine.backgroundColor = .whiteColor()
horizontalLine.center = backgroundColorView.center
backgroundColorView.addSubview(horizontalLine)
}
}
...@@ -19,141 +19,29 @@ ...@@ -19,141 +19,29 @@
import UIKit import UIKit
public class FabButton : MaterialButton { public class FabButton : MaterialButton {
/**
var lineWidth: CGFloat = 2.0 :name: lineWidth
*/
public convenience init() { public var lineWidth: CGFloat = 2
self.init(frame: CGRectZero)
} //
// :name: prepareButton
public override func drawRect(rect: CGRect) { //
setupContext(rect) internal override func prepareButton() {
setupBackgroundColorView() super.prepareButton()
setupPlus() color = .redColor()
} pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = bounds.width / 2
public required init(coder aDecoder: NSCoder) { }
super.init(coder: aDecoder)
initialize() //
applyShadow() // :name: pulseTouches
} //
internal override func pulseTouches(touches: Set<NSObject>) {
public required override init(frame: CGRect) { super.pulseTouches(touches)
super.init(frame: frame) UIView.animateWithDuration(0.3, animations: {
initialize()
applyShadow()
}
func initialize() {
color = UIColor.redColor()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
}
func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect)
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView!.frame = bounds
backgroundColorView!.layer.cornerRadius = bounds.width / 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
insertSubview(backgroundColorView!, atIndex: 0)
}
// I make the + with two views because
// The label is not actually vertically and horizontally aligned
// Quick hack instead of subclassing UILabel and override drawTextInRect
func setupPlus() {
setupVerticalLine()
setupHorizontalLine()
}
func setupVerticalLine() {
verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView!.frame) / 3.0))
verticalLine!.backgroundColor = UIColor.whiteColor()
verticalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(verticalLine!)
}
func setupHorizontalLine() {
horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView!.frame) / 3.0, lineWidth))
horizontalLine!.backgroundColor = UIColor.whiteColor()
horizontalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(horizontalLine!)
}
func applyShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3) self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1) self.transform = CGAffineTransformMakeScale(1.1, 1.1)
}, })
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: { _ in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
} }
} }
...@@ -19,104 +19,30 @@ ...@@ -19,104 +19,30 @@
import UIKit import UIKit
public class FlatButton : MaterialButton { public class FlatButton : MaterialButton {
/**
:name: textColor
*/
public var textColor: UIColor? public var textColor: UIColor?
public override func drawRect(rect: CGRect) { //
setupContext(rect) // :name: prepareButton
setupBackgroundColorView() //
} internal override func prepareButton() {
super.prepareButton()
public required init(coder aDecoder: NSCoder) { pulseColor = .whiteColor()
super.init(coder: aDecoder) backgroundColorView.layer.cornerRadius = 3
initialize() }
applyShadow()
} //
// :name: pulseTouches
public required override init(frame: CGRect) { //
super.init(frame: frame) internal override func pulseTouches(touches: Set<NSObject>) {
initialize() super.pulseTouches(touches)
applyShadow() textColor = titleLabel?.textColor
}
func initialize() {
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
}
func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
backgroundColorView!.frame = self.bounds
backgroundColorView!.layer.cornerRadius = 3.0
backgroundColorView!.backgroundColor = UIColor.clearColor()
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
self.insertSubview(backgroundColorView!, atIndex: 0)
}
func applyShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView!.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal) self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
}, 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
self.setTitleColor(self.textColor, forState: .Normal)
}) { (finished) -> Void in
self.pulseView!.removeFromSuperview()
self.pulseView = nil
}
} }
} }
...@@ -19,11 +19,174 @@ ...@@ -19,11 +19,174 @@
import UIKit import UIKit
public class MaterialButton : UIButton { public class MaterialButton : UIButton {
//
// :name: backgroundColorView
//
internal lazy var backgroundColorView: UIView = UIView()
//
// :name: pulseView
//
internal var pulseView: UIView?
/**
:name: color
*/
public var color: UIColor? public var color: UIColor?
/**
:name: pulseColor
*/
public var pulseColor: UIColor? public var pulseColor: UIColor?
internal var pulseView: UIView? /**
internal var verticalLine: UIView? :name: init
internal var horizontalLine: UIView? */
internal var backgroundColorView: UIView? public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public required override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectZero)
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
/**
:name: touchesEnded
*/
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
/**
:name: drawRect
*/
final public override func drawRect(rect: CGRect) {
prepareContext(rect)
prepareShadow()
prepareButton()
prepareBackgroundColorView()
}
//
// :name: prepareButton
//
internal func prepareButton() {
backgroundColorView.frame = bounds
}
//
// :name: pulseTouches
//
internal func pulseTouches(touches: Set<NSObject>) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
}
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func prepareBackgroundColorView() {
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
}
//
// :name: prepareView
//
private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
}
//
// :name: prepareShadow
//
private func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
//
// :name: prepareContext
//
private func prepareContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect)
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
//
// :name: shrink
//
private func shrink() {
UIView.animateWithDuration(0.3,
delay: 0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity
},
completion: nil
)
}
//
// :name: removePulse
//
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
} }
...@@ -19,112 +19,32 @@ ...@@ -19,112 +19,32 @@
import UIKit import UIKit
public class RaisedButton : MaterialButton { public class RaisedButton : MaterialButton {
public override func drawRect(rect: CGRect) { /**
setupContext(rect) :name: textColor
setupBackgroundColorView() */
} public var textColor: UIColor?
public required init(coder aDecoder: NSCoder) { //
super.init(coder: aDecoder) // :name: prepareButton
initialize() //
applyShadow() internal override func prepareButton() {
} super.prepareButton()
color = .redColor()
public required override init(frame: CGRect) { pulseColor = .whiteColor()
super.init(frame: frame) backgroundColorView.layer.cornerRadius = 3
initialize() }
applyShadow()
} //
// :name: pulseTouches
func initialize() { //
color = UIColor.redColor() internal override func pulseTouches(touches: Set<NSObject>) {
backgroundColorView = UIView() super.pulseTouches(touches)
pulseColor = UIColor.whiteColor() textColor = titleLabel?.textColor
setTranslatesAutoresizingMaskIntoConstraints(false) UIView.animateWithDuration(0.3, animations: {
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
private func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func setupBackgroundColorView() {
backgroundColorView!.frame = self.bounds
backgroundColorView!.layer.cornerRadius = 3.0
backgroundColorView!.backgroundColor = color!
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
self.insertSubview(backgroundColorView!, atIndex: 0)
}
private func applyShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
private func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
}, self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
completion: nil })
)
}
private func shrink() {
UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity
},
completion: nil
)
}
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { () -> Void in
self.pulseView!.alpha = 0.0
}) { _ in
self.pulseView!.removeFromSuperview()
self.pulseView = nil
}
} }
} }
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