Commit 9756078e by Daniel Dahan

development: added Pulse object to replace pulse behavior

parent 10bbe53e
......@@ -58,12 +58,12 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.white)
favoriteButton.pulseColor = Color.white
favoriteButton.pulse.color = Color.white
}
private func prepareShareButton() {
shareButton = IconButton(image: Icon.cm.share, tintColor: Color.white)
shareButton.pulseColor = Color.white
shareButton.pulse.color = Color.white
}
private func prepareTitleLabel() {
......
......@@ -80,7 +80,7 @@ class ViewController: UIViewController {
private func prepareRaisedButton() {
let button = RaisedButton(title: "Raised Button", titleColor: Color.white)
button.pulseColor = Color.white
button.pulse.color = Color.white
button.backgroundColor = Color.blue.base
view.layout(button)
......
......@@ -64,7 +64,7 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.blue.base)
favoriteButton.pulseColor = Color.blue.base
favoriteButton.pulse.color = Color.blue.base
}
private func prepareBottomBar() {
......
......@@ -81,7 +81,7 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.grey.base)
favoriteButton.pulseColor = Color.grey.base
favoriteButton.pulse.color = Color.grey.base
}
private func prepareBottomBar() {
......
......@@ -77,7 +77,7 @@ class RootViewController: UIViewController {
private func prepareNextButton() {
nextButton = FlatButton()
nextButton.pulseAnimation = .none
nextButton.pulse.animation = .none
nextButton.addTarget(self, action: #selector(handleNextButton), for: .touchUpInside)
view.layout(nextButton).edges()
}
......
......@@ -34,7 +34,7 @@ import Material
class PhotoLibraryCollectionViewCell: CollectionViewCell {
open override func prepare() {
super.prepare()
pulseAnimation = .backing
pulse.animation = .backing
contentsGravityPreset = .ResizeAspectFill
}
}
......@@ -51,7 +51,7 @@ class RootViewController: UIViewController {
private func prepareUndoButton() {
undoButton = FlatButton(title: "Undo", titleColor: Color.yellow.base)
undoButton.pulseAnimation = .backing
undoButton.pulse.animation = .backing
undoButton.titleLabel?.font = RobotoFont.regular(with: 14)
}
......
......@@ -48,15 +48,15 @@ class ViewController: UIViewController {
private func prepareButtons() {
let btn1 = FlatButton(title: "Library", titleColor: Color.blueGrey.base)
btn1.pulseAnimation = .none
btn1.pulse.animation = .none
buttons.append(btn1)
let btn2 = FlatButton(title: "Photo", titleColor: Color.blueGrey.base)
btn2.pulseAnimation = .none
btn2.pulse.animation = .none
buttons.append(btn2)
let btn3 = FlatButton(title: "Video", titleColor: Color.blueGrey.base)
btn3.pulseAnimation = .none
btn3.pulse.animation = .none
buttons.append(btn3)
}
......
......@@ -18,6 +18,7 @@
962864621D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
962864631D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
9631A7C11D95E3AC00CFB109 /* PresenterCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */; };
9631A7C71D95E5D900CFB109 /* Pulse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9631A7C61D95E5D900CFB109 /* Pulse.swift */; };
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; };
......@@ -228,6 +229,7 @@
9628645E1D540AF300690B69 /* DynamicFontType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFontType.swift; sourceTree = "<group>"; };
962864611D54111D00690B69 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresenterCard.swift; sourceTree = "<group>"; };
9631A7C61D95E5D900CFB109 /* Pulse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pulse.swift; sourceTree = "<group>"; };
96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -414,6 +416,16 @@
name = BottomTabBar;
sourceTree = "<group>";
};
9631A7C51D95E5C400CFB109 /* Pulse */ = {
isa = PBXGroup;
children = (
9631A7C61D95E5D900CFB109 /* Pulse.swift */,
96BCB7841CB40DC500C806FE /* PulseView.swift */,
96BCB7821CB40DC500C806FE /* PulseAnimation.swift */,
);
name = Pulse;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
isa = PBXGroup;
children = (
......@@ -561,6 +573,7 @@
96BCB8011CB40F1700C806FE /* Navigation */,
962DDD071D6FBBB7001C307C /* Page */,
96EA9A411D4E68E60052C74D /* PhotoLibrary */,
9631A7C51D95E5C400CFB109 /* Pulse */,
96264BE51D833CFF00576F37 /* Reminders */,
963FBF031D6696EF008F8512 /* SearchBar */,
963FBEFB1D6694E8008F8512 /* Snackbar */,
......@@ -710,7 +723,6 @@
96BCB76D1CB40DC500C806FE /* Animation.swift */,
96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */,
96BCB77E1CB40DC500C806FE /* KeyframeAnimation.swift */,
96BCB7821CB40DC500C806FE /* PulseAnimation.swift */,
96E3C39D1D3A1D0C0086A024 /* BasicAnimation.swift */,
);
name = Animation;
......@@ -743,7 +755,6 @@
isa = PBXGroup;
children = (
96BCB78C1CB40DC500C806FE /* View.swift */,
96BCB7841CB40DC500C806FE /* PulseView.swift */,
);
name = View;
sourceTree = "<group>";
......@@ -1103,6 +1114,7 @@
96BCB7C81CB40DC500C806FE /* Label.swift in Sources */,
96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */,
96BCB7BD1CB40DC500C806FE /* CollectionViewDelegate.swift in Sources */,
9631A7C71D95E5D900CFB109 /* Pulse.swift in Sources */,
961F18E81CD93E3E008927C5 /* ErrorTextField.swift in Sources */,
96BCB7D01CB40DC500C806FE /* InterimSpace.swift in Sources */,
96BCB7E81CB40DC500C806FE /* Toolbar.swift in Sources */,
......
......@@ -40,19 +40,9 @@ open class Button: UIButton {
*/
open private(set) lazy var visualLayer = CAShapeLayer()
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
/// The opacity value for the pulse animation.
@IBInspectable
open var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
public var pulseAnimation = PulseAnimation.pointWithBacking
/// A Pulse reference.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
......@@ -178,13 +168,13 @@ open class Button: UIButton {
from the center.
*/
open func pulse(point: CGPoint? = nil) {
let p = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -196,7 +186,7 @@ open class Button: UIButton {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -207,7 +197,7 @@ open class Button: UIButton {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -218,7 +208,7 @@ open class Button: UIButton {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
......@@ -40,19 +40,9 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open private(set) lazy var visualLayer = CAShapeLayer()
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
/// The opcaity value for the pulse animation.
@IBInspectable
open var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation = PulseAnimation.pointWithBacking
/// A Pulse reference.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
/**
A property that manages an image for the visualLayer's contents
......@@ -216,12 +206,12 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -233,7 +223,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -244,7 +234,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -255,7 +245,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -267,7 +257,7 @@ open class CollectionReusableView: UICollectionReusableView {
*/
open func prepare() {
contentScaleFactor = Device.scale
pulseAnimation = .none
pulse.animation = .none
prepareVisualLayer()
}
......
......@@ -43,19 +43,9 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open private(set) lazy var visualLayer = CAShapeLayer()
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
/// The opcaity value for the pulse animation.
@IBInspectable
open var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation = PulseAnimation.pointWithBacking
/// A Pulse reference.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
/**
A property that manages an image for the visualLayer's contents
......@@ -226,12 +216,12 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -243,7 +233,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -254,7 +244,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -265,7 +255,7 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
......@@ -48,7 +48,7 @@ open class Divider {
/// A reference to the height.
public var height: CGFloat
/// Divider color.
/// A UIColor.
open var color: UIColor? {
get {
return line?.backgroundColor
......
......@@ -42,8 +42,8 @@ open class FabButton: Button {
super.prepare()
depthPreset = .depth1
shapePreset = .circle
pulseAnimation = .centerWithBacking
pulseColor = Color.white
pulse.animation = .centerWithBacking
pulse.color = Color.white
tintColor = Color.white
backgroundColor = Color.red.base
}
......
......@@ -40,6 +40,6 @@ open class IconButton: Button {
*/
open override func prepare() {
super.prepare()
pulseAnimation = .center
pulse.animation = .center
}
}
......@@ -36,7 +36,7 @@ private var PageTabBarItemKey: UInt8 = 0
open class PageTabBarItem: FlatButton {
open override func prepare() {
super.prepare()
pulseAnimation = .none
pulse.animation = .none
}
}
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
open class Pulse {
/// An Array of layers.
internal lazy var layers = [CAShapeLayer]()
/// A UIColor.
@IBInspectable
open var color = Color.grey.base
/// A reference to the PulseAnimation.
open var animation = PulseAnimation.pointWithBacking
/// The opcaity value for the pulse animation.
@IBInspectable
open var opacity: CGFloat = 0.18
}
......@@ -46,35 +46,34 @@ internal extension Animation {
/**
Triggers the expanding animation.
- Parameter layer: Container CALayer.
- Parameter visualLayer: A CAShapeLayer for the pulseLayer.
- Parameter pulseColor: The UIColor for the pulse.
- Parameter visualLayer: A CAShapeLayer.
- Parameter point: A point to pulse from.
- Parameter width: Container width.
- Parameter height: Container height.
- Parameter duration: Animation duration.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
- Parameter pulse: A Pulse instance.
*/
internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor, pulseOpacity: CGFloat, point: CGPoint, width: CGFloat, height: CGFloat, pulseLayers: inout Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
guard .none != pulseAnimation else {
internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, point: CGPoint, width: CGFloat, height: CGFloat, pulse: inout Pulse) {
guard .none != pulse.animation else {
return
}
let n = .center == pulseAnimation ? width < height ? width : height : width < height ? height : width
let n = .center == pulse.animation ? width < height ? width : height : width < height ? height : width
let bLayer = CAShapeLayer()
let pLayer = CAShapeLayer()
bLayer.addSublayer(pLayer)
pulseLayers.insert(bLayer, at: 0)
pulse.layers.insert(bLayer, at: 0)
visualLayer.addSublayer(bLayer)
visualLayer.masksToBounds = !(.centerRadialBeyondBounds == pulseAnimation || .radialBeyondBounds == pulseAnimation)
visualLayer.masksToBounds = !(.centerRadialBeyondBounds == pulse.animation || .radialBeyondBounds == pulse.animation)
Animation.animationDisabled(animations: {
Animation.animationDisabled(animations: { [visualLayer = visualLayer, pulse = pulse] in
bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRect(x: 0, y: 0, width: n, height: n)
switch pulseAnimation {
switch pulse.animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds:
pLayer.position = CGPoint(x: width / 2, y: height / 2)
default:
......@@ -82,21 +81,21 @@ internal extension Animation {
}
pLayer.cornerRadius = n / 2
pLayer.backgroundColor = pulseColor.withAlphaComponent(pulseOpacity).cgColor
pLayer.backgroundColor = pulse.color.withAlphaComponent(pulse.opacity).cgColor
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 0, y: 0))
})
bLayer.setValue(false, forKey: "animated")
let duration: CFTimeInterval = .center == pulseAnimation ? 0.16125 : 0.325
let duration: CFTimeInterval = .center == pulse.animation ? 0.16125 : 0.325
switch pulseAnimation {
switch pulse.animation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(pulseOpacity / 2), duration: duration), forKey: nil)
bLayer.add(Animation.backgroundColor(color: pulse.color.withAlphaComponent(pulse.opacity / 2), duration: duration), forKey: nil)
default:break
}
switch pulseAnimation {
switch pulse.animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Animation.scale(scale: 1, duration: duration), forKey: nil)
default:break
......@@ -110,11 +109,11 @@ internal extension Animation {
/**
Triggers the contracting animation.
- Parameter layer: Container CALayer.
- Parameter pulseColor: The UIColor for the pulse.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
- Parameter visualLayer: A CAShapeLayer.
- Parameter pulse: A Pulse instance.
*/
internal static func pulseContractAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor, pulseLayers: inout Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
guard let bLayer = pulseLayers.popLast() else {
internal static func pulseContractAnimation(layer: CALayer, visualLayer: CALayer, pulse: inout Pulse) {
guard let bLayer = pulse.layers.popLast() else {
return
}
......@@ -122,24 +121,24 @@ internal extension Animation {
return
}
Animation.delay(time: animated ? 0 : 0.15) {
Animation.delay(time: animated ? 0 : 0.15) { [pulse = pulse] in
guard let pLayer = bLayer.sublayers?.first as? CAShapeLayer else {
return
}
let duration = 0.325
switch pulseAnimation {
switch pulse.animation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(0), duration: duration), forKey: nil)
bLayer.add(Animation.backgroundColor(color: pulse.color.withAlphaComponent(0), duration: duration), forKey: nil)
default:break
}
switch pulseAnimation {
switch pulse.animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Animation.animationGroup(animations: [
Animation.scale(scale: .center == pulseAnimation ? 1 : 1.325),
Animation.backgroundColor(color: pulseColor.withAlphaComponent(0))
Animation.scale(scale: .center == pulse.animation ? 1 : 1.325),
Animation.backgroundColor(color: pulse.color.withAlphaComponent(0))
], duration: duration), forKey: nil)
default:break
}
......
......@@ -31,19 +31,9 @@
import UIKit
open class PulseView: View {
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
/// The opcaity value for the pulse animation.
@IBInspectable
open var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
/// A Pulse reference.
@IBInspectable
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation = PulseAnimation.pointWithBacking
open internal(set) lazy var pulse: Pulse = Pulse()
/**
Triggers the pulse animation.
......@@ -52,12 +42,12 @@ open class PulseView: View {
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -69,7 +59,7 @@ open class PulseView: View {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -80,7 +70,7 @@ open class PulseView: View {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -91,6 +81,6 @@ open class PulseView: View {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
}
......@@ -413,7 +413,7 @@ open class Switch: UIControl {
/// Prepares the button.
private func prepareButton() {
button.pulseAnimation = .none
button.pulse.animation = .none
button.addTarget(self, action: #selector(handleTouchUpInside), for: .touchUpInside)
button.addTarget(self, action: #selector(handleTouchDragInside), for: .touchDragInside)
button.addTarget(self, action: #selector(handleTouchUpOutsideOrCanceled), for: .touchCancel)
......
......@@ -39,19 +39,9 @@ open class TableViewCell: UITableViewCell {
*/
open private(set) lazy var visualLayer = CAShapeLayer()
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
/// The opcaity value for the pulse animation.
@IBInspectable
open var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
/// A Pulse reference.
@IBInspectable
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation = PulseAnimation.pointWithBacking
open internal(set) lazy var pulse: Pulse = Pulse()
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
......@@ -100,12 +90,12 @@ open class TableViewCell: UITableViewCell {
*/
open func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: p, width: width, height: height, pulse: &pulse)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulse: &s.pulse)
}
}
......@@ -117,7 +107,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulse: &pulse)
}
/**
......@@ -128,7 +118,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......@@ -139,7 +129,7 @@ open class TableViewCell: UITableViewCell {
*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulse: &pulse)
}
/**
......
......@@ -207,7 +207,7 @@ open class TextField: UITextField {
if nil == clearIconButton {
clearIconButton = IconButton(image: Icon.cm.clear, tintColor: placeholderColor)
clearIconButton!.contentEdgeInsets = .zero
clearIconButton!.pulseAnimation = .center
clearIconButton!.pulse.animation = .center
clearButtonMode = .never
rightViewMode = .whileEditing
rightView = clearIconButton
......@@ -242,7 +242,7 @@ open class TextField: UITextField {
if nil == visibilityIconButton {
visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54))
visibilityIconButton!.contentEdgeInsets = .zero
visibilityIconButton!.pulseAnimation = .center
visibilityIconButton!.pulse.animation = .center
isSecureTextEntry = true
clearButtonMode = .never
rightViewMode = .whileEditing
......
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