Skip to content

Commit

Permalink
Added isActive() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakarang committed Mar 7, 2016
1 parent 08c26c7 commit 66a066a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Pod/Classes/SAConfettiView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import QuartzCore

public class SAConfettiView: UIView {

public enum ConfettiType {
case Confetti
case Triangle
Expand All @@ -23,17 +23,18 @@ public class SAConfettiView: UIView {
public var colors: [UIColor]!
public var intensity: Float!
public var type: ConfettiType!

private var active :Bool!

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

public override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

func setup() {
colors = [UIColor(red:0.95, green:0.40, blue:0.27, alpha:1.0),
UIColor(red:1.00, green:0.78, blue:0.36, alpha:1.0),
Expand All @@ -42,32 +43,35 @@ public class SAConfettiView: UIView {
UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)]
intensity = 0.5
type = .Confetti
active = false
}

public func startConfetti() {
emitter = CAEmitterLayer()

emitter.emitterPosition = CGPoint(x: frame.size.width / 2.0, y: 0)
emitter.emitterShape = kCAEmitterLayerLine
emitter.emitterSize = CGSize(width: frame.size.width, height: 1)

var cells = [CAEmitterCell]()
for color in colors {
cells.append(confettiWithColor(color))
}

emitter.emitterCells = cells
layer.addSublayer(emitter)
active = true
}

public func stopConfetti() {
emitter?.birthRate = 0
active = false
}

func imageForType(type: ConfettiType) -> UIImage? {

var fileName: String!

switch type {
case .Confetti:
fileName = "confetti"
Expand All @@ -80,7 +84,7 @@ public class SAConfettiView: UIView {
case let .Image(customImage):
return customImage
}

let path = NSBundle(forClass: SAConfettiView.self).pathForResource("SAConfettiView", ofType: "bundle")
let bundle = NSBundle(path: path!)
let imagePath = bundle?.pathForResource(fileName, ofType: "png")
Expand All @@ -91,7 +95,7 @@ public class SAConfettiView: UIView {
}
return nil
}

func confettiWithColor(color: UIColor) -> CAEmitterCell {
let confetti = CAEmitterCell()
confetti.birthRate = 6.0 * intensity
Expand All @@ -110,4 +114,7 @@ public class SAConfettiView: UIView {
return confetti
}

public func isActive() -> Bool {
return self.active
}
}

0 comments on commit 66a066a

Please sign in to comment.