Skip to content

Commit

Permalink
Merge branch 'master' into pr/2
Browse files Browse the repository at this point in the history
Conflicts:

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallClipR
otateMultiple.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallClipR
otatePulse.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallPulse
Rise.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallSpinF
adeLoader.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallZigZa
g.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationBallZigZa
gDeflect.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationLineSpinF
adeLoader.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationSquareSpi
n.swift

NVActivityIndicatorView/Animations/NVActivityIndicatorAnimationTriangleS
kewSpin.swift
	NVActivityIndicatorView/NVActivityIndicatorShape.swift
	NVActivityIndicatorView/NVActivityIndicatorView.swift
  • Loading branch information
ninjaprox committed Sep 18, 2015
2 parents f2515eb + 1f084c8 commit f00845b
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 117 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log

## [v1.3](https://github.com/ninjaprox/NVActivityIndicatorView/releases/tag/v1.3)
* More convenient constructor
* Hide when stopped option

## [v1.2](https://github.com/ninjaprox/NVActivityIndicatorView/releases/tag/v1.2)
* Fix issue when using as framework
* Set default animation type to pacman
* Add documentation

## [v1.1](https://github.com/ninjaprox/NVActivityIndicatorView/releases/tag/v1.1)

* Change project structure to work well with CocoaPods
Expand All @@ -8,4 +17,4 @@
## [v1.0](https://github.com/ninjaprox/NVActivityIndicatorView/releases/tag/v1.0)

* Initial release
* Full implementations of 28 loaders from loaders.css
* Full implementations of 28 loaders from loaders.css
26 changes: 2 additions & 24 deletions NVActivityIndicatorView.podspec
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.name = "NVActivityIndicatorView"
s.version = "1.1"
s.version = "1.3"
s.summary = "A collection of nice loading animations"

s.homepage = "https://github.com/ninjaprox/NVActivityIndicatorView"
s.screenshots = "https://raw.githubusercontent.com/ninjaprox/NVActivityIndicatorView/master/Demo.gif"

# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.license = { :type => "MIT" }

# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.author = { "Nguyen Vinh" => "[email protected]" }
s.social_media_url = "http://twitter.com/ninjaprox"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.platform = :ios, '8.0'

# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.source = { :git => "https://github.com/ninjaprox/NVActivityIndicatorView.git", :tag => "v1.1" }

# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.source = { :git => "https://github.com/ninjaprox/NVActivityIndicatorView.git", :tag => "v1.3" }
s.source_files = "NVActivityIndicatorView/**/*.swift"

# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.frameworks = "UIKit", "QuartzCore"

# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

s.requires_arc = true

end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class NVActivityIndicatorAnimationBallClipRotateMultiple: NVActivityIndicatorAni
let bigCircleSize: CGFloat = size.width
let smallCircleSize: CGFloat = size.width / 2
let longDuration: CFTimeInterval = 1
let shortDuration: CFTimeInterval = 0.5
let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

circleOf(shape: .RingTwoHalfHorizontal,
Expand All @@ -31,7 +30,7 @@ class NVActivityIndicatorAnimationBallClipRotateMultiple: NVActivityIndicatorAni
color: color, reverse: true)
}

func createAnimationIn(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, reverse: Bool) -> CAAnimation {
func createAnimationIn(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, reverse: Bool) -> CAAnimation {
// Scale animation
let scaleAnimation = CAKeyframeAnimation(keyPath: "transform.scale")

Expand Down Expand Up @@ -63,7 +62,7 @@ class NVActivityIndicatorAnimationBallClipRotateMultiple: NVActivityIndicatorAni
return animation
}

func circleOf(shape shape: NVActivityIndicatorShape, duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGFloat, color: UIColor, reverse: Bool) {
func circleOf(shape shape: NVActivityIndicatorShape, duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGFloat, color: UIColor, reverse: Bool) {
let circle = shape.createLayerWith(size: CGSize(width: size, height: size), color: color)
let frame = CGRect(x: (layer.bounds.size.width - size) / 2,
y: (layer.bounds.size.height - size) / 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NVActivityIndicatorAnimationBallClipRotatePulse: NVActivityIndicatorAnimat
bigCircleWith(duration: duration, timingFunction: timingFunction, layer: layer, size: size, color: color)
}

func smallCircleWith(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGSize, color: UIColor) {
func smallCircleWith(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGSize, color: UIColor) {
// Animation
let animation = CAKeyframeAnimation(keyPath:"transform.scale")

Expand All @@ -42,7 +42,7 @@ class NVActivityIndicatorAnimationBallClipRotatePulse: NVActivityIndicatorAnimat
layer.addSublayer(circle)
}

func bigCircleWith(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGSize, color: UIColor) {
func bigCircleWith(duration duration: CFTimeInterval, timingFunction: CAMediaTimingFunction, layer: CALayer, size: CGSize, color: UIColor) {
// Scale animation
let scaleAnimation = CAKeyframeAnimation(keyPath:"transform.scale")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NVActivityIndicatorAnimationBallPulseRise: NVActivityIndicatorAnimationDel
}
}

func oddAnimation(duration duration: CFTimeInterval, deltaY: CGFloat, timingFunction: CAMediaTimingFunction) -> CAAnimation {
func oddAnimation(duration duration: CFTimeInterval, deltaY: CGFloat, timingFunction: CAMediaTimingFunction) -> CAAnimation {
// Scale animation
let scaleAnimation = CAKeyframeAnimation(keyPath: "transform.scale")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class NVActivityIndicatorAnimationBallSpinFadeLoader: NVActivityIndicatorAnimati
}
}

func circleAt(angle angle: CGFloat, size: CGFloat, origin: CGPoint, containerSize: CGSize, color: UIColor) -> CALayer {
func circleAt(angle angle: CGFloat, size: CGFloat, origin: CGPoint, containerSize: CGSize, color: UIColor) -> CALayer {
let radius = containerSize.width / 2
let circle = NVActivityIndicatorShape.Circle.createLayerWith(size: CGSize(width: size, height: size), color: color)
let frame = CGRect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NVActivityIndicatorAnimationBallZigZag: NVActivityIndicatorAnimationDelega
circleAt(frame: frame, layer: layer, size: CGSize(width: circleSize, height: circleSize), color: color, animation: animation)
}

func circleAt(frame frame: CGRect, layer: CALayer, size: CGSize, color: UIColor, animation: CAAnimation) {
func circleAt(frame frame: CGRect, layer: CALayer, size: CGSize, color: UIColor, animation: CAAnimation) {
let circle = NVActivityIndicatorShape.Circle.createLayerWith(size: size, color: color)

circle.frame = frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NVActivityIndicatorAnimationBallZigZagDeflect: NVActivityIndicatorAnimatio
circleAt(frame: frame, layer: layer, size: CGSize(width: circleSize, height: circleSize), color: color, animation: animation)
}

func circleAt(frame frame: CGRect, layer: CALayer, size: CGSize, color: UIColor, animation: CAAnimation) {
func circleAt(frame frame: CGRect, layer: CALayer, size: CGSize, color: UIColor, animation: CAAnimation) {
let circle = NVActivityIndicatorShape.Circle.createLayerWith(size: size, color: color)

circle.frame = frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NVActivityIndicatorAnimationLineSpinFadeLoader: NVActivityIndicatorAnimati
}
}

func lineAt(angle angle: CGFloat, size: CGSize, origin: CGPoint, containerSize: CGSize, color: UIColor) -> CALayer {
func lineAt(angle angle: CGFloat, size: CGSize, origin: CGPoint, containerSize: CGSize, color: UIColor) -> CALayer {
let radius = containerSize.width / 2
let lineContainerSize = CGSize(width: max(size.width, size.height), height: max(size.width, size.height))
let lineContainer = CALayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class NVActivityIndicatorAnimationSquareSpin: NVActivityIndicatorAnimationDelega
layer.addSublayer(square)
}

func createRotateXTransform(angle angle: CGFloat) -> CATransform3D {
func createRotateXTransform(angle angle: CGFloat) -> CATransform3D {
var transform = CATransform3DMakeRotation(angle, 1, 0, 0)

transform.m34 = CGFloat(-1) / 100

return transform
}

func createRotateYTransform(angle angle: CGFloat) -> CATransform3D {
func createRotateYTransform(angle angle: CGFloat) -> CATransform3D {
var transform = CATransform3DMakeRotation(angle, 0, 1, 0)

transform.m34 = CGFloat(-1) / 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class NVActivityIndicatorAnimationTriangleSkewSpin: NVActivityIndicatorAnimation
layer.addSublayer(triangle)
}

func createRotateXTransform(angle angle: CGFloat) -> CATransform3D {
func createRotateXTransform(angle angle: CGFloat) -> CATransform3D {
var transform = CATransform3DMakeRotation(angle, 1, 0, 0)

transform.m34 = CGFloat(-1) / 100

return transform
}

func createRotateYTransform(angle angle: CGFloat) -> CATransform3D {
func createRotateYTransform(angle angle: CGFloat) -> CATransform3D {
var transform = CATransform3DMakeRotation(angle, 0, 1, 0)

transform.m34 = CGFloat(-1) / 100
Expand Down
8 changes: 1 addition & 7 deletions NVActivityIndicatorView/NVActivityIndicatorShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum NVActivityIndicatorShape {
case Line
case Pacman

func createLayerWith(size size: CGSize, color: UIColor) -> CALayer {
func createLayerWith(size size: CGSize, color: UIColor) -> CALayer {
let layer: CAShapeLayer = CAShapeLayer()
var path: UIBezierPath = UIBezierPath()
let lineWidth: CGFloat = 2
Expand All @@ -34,8 +34,6 @@ enum NVActivityIndicatorShape {
clockwise: false);
layer.fillColor = color.CGColor
case .CircleSemi:
_ = CGFloat(size.width / 2)

path.addArcWithCenter(CGPoint(x: size.width / 2, y: size.height / 2),
radius: size.width / 2,
startAngle: CGFloat(-M_PI / 6),
Expand All @@ -53,8 +51,6 @@ enum NVActivityIndicatorShape {
layer.strokeColor = color.CGColor
layer.lineWidth = lineWidth
case .RingTwoHalfVertical:
_ = CGFloat(size.width / 2)

path.addArcWithCenter(CGPoint(x: size.width / 2, y: size.height / 2),
radius:size.width / 2,
startAngle:CGFloat(-3 * M_PI_4),
Expand All @@ -73,8 +69,6 @@ enum NVActivityIndicatorShape {
layer.strokeColor = color.CGColor
layer.lineWidth = lineWidth
case .RingTwoHalfHorizontal:
_ = size.width / 2

path.addArcWithCenter(CGPoint(x: size.width / 2, y: size.height / 2),
radius:size.width / 2,
startAngle:CGFloat(3 * M_PI_4),
Expand Down
150 changes: 86 additions & 64 deletions NVActivityIndicatorView/NVActivityIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

enum NVActivityIndicatorType {
public enum NVActivityIndicatorType {
case Blank
case BallPulse
case BallGridPulse
Expand Down Expand Up @@ -38,70 +38,9 @@ enum NVActivityIndicatorType {
case Pacman
case BallGridBeat
case SemiCircleSpin
}

class NVActivityIndicatorView: UIView {
private let DEFAULT_TYPE: NVActivityIndicatorType = .Blank
private let DEFAULT_COLOR = UIColor.whiteColor()
private let DEFAULT_SIZE: CGSize = CGSize(width: 40, height: 40)

private var type: NVActivityIndicatorType
private var color: UIColor
private var size: CGSize

var animating: Bool = false

required init?(coder aDecoder: NSCoder) {
self.type = DEFAULT_TYPE
self.color = DEFAULT_COLOR
self.size = DEFAULT_SIZE
super.init(coder: aDecoder);
}

init(frame: CGRect, type: NVActivityIndicatorType, color: UIColor?, size: CGSize?) {
self.type = type
self.color = DEFAULT_COLOR
self.size = DEFAULT_SIZE
super.init(frame: frame)

if let _color = color {
self.color = _color
}
if let _size = size {
self.size = _size
}
}

convenience init(frame: CGRect, type: NVActivityIndicatorType, color: UIColor?) {
self.init(frame: frame, type: type, color: color, size: nil)
}

convenience init(frame: CGRect, type: NVActivityIndicatorType) {
self.init(frame: frame, type: type, color: nil)
}

func startAnimation() {
if (self.layer.sublayers == nil) {
setUpAnimation()
}
self.layer.speed = 1
self.animating = true
}

func stopAnimation() {
self.layer.speed = 0
self.animating = false
}

private func setUpAnimation() {
let animation: protocol<NVActivityIndicatorAnimationDelegate> = animationOfType(self.type)

self.layer.sublayers = nil
animation.setUpAnimationInLayer(self.layer, size: self.size, color: self.color)
}

private func animationOfType(type: NVActivityIndicatorType) -> protocol<NVActivityIndicatorAnimationDelegate> {
switch type {
private func animation() -> NVActivityIndicatorAnimationDelegate {
switch self {
case .Blank:
return NVActivityIndicatorAnimationBlank()
case .BallPulse:
Expand Down Expand Up @@ -163,3 +102,86 @@ class NVActivityIndicatorView: UIView {
}
}
}

public class NVActivityIndicatorView: UIView {
private static let DEFAULT_TYPE: NVActivityIndicatorType = .Pacman
private static let DEFAULT_COLOR = UIColor.whiteColor()
private static let DEFAULT_SIZE: CGSize = CGSize(width: 40, height: 40)

private var type: NVActivityIndicatorType
private var color: UIColor
private var size: CGSize

var animating: Bool = false
var hidesWhenStopped: Bool = true

/**
Create a activity indicator view with default type, color and size
This is used by storyboard to initiate the view

- Default type is pacman\n
- Default color is white\n
- Default size is 40

- parameter decoder:

- returns: The activity indicator view
*/
required public init?(coder aDecoder: NSCoder) {
self.type = NVActivityIndicatorView.DEFAULT_TYPE
self.color = NVActivityIndicatorView.DEFAULT_COLOR
self.size = NVActivityIndicatorView.DEFAULT_SIZE
super.init(coder: aDecoder);
}

/**
Create a activity indicator view with specified type, color, size and size

- parameter frame: view's frame
- parameter type: animation type, value of NVActivityIndicatorType enum. Default type is pacman.
- parameter color: color of activity indicator view. Default color is white.
- parameter size: actual size of animation in view. Default size is 40

- returns: The activity indicator view
*/
public init(frame: CGRect, type: NVActivityIndicatorType = DEFAULT_TYPE, color: UIColor = DEFAULT_COLOR, size: CGSize = DEFAULT_SIZE) {
self.type = type
self.color = color
self.size = size
super.init(frame: frame)
}

/**
Start animation
*/
public func startAnimation() {
if hidesWhenStopped && hidden {
hidden = false
}
if (self.layer.sublayers == nil) {
setUpAnimation()
}
self.layer.speed = 1
self.animating = true
}

/**
Stop animation
*/
public func stopAnimation() {
self.layer.speed = 0
self.animating = false
if hidesWhenStopped && !hidden {
hidden = true
}
}

// MARK: Privates

private func setUpAnimation() {
let animation: protocol<NVActivityIndicatorAnimationDelegate> = self.type.animation()

self.layer.sublayers = nil
animation.setUpAnimationInLayer(self.layer, size: self.size, color: self.color)
}
}
Loading

0 comments on commit f00845b

Please sign in to comment.