Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplification and refactoring #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Pod/Classes/ConfettiType.swift
@@ -0,0 +1,36 @@
//
// ConfettiType.swift
// Pods
//
// Created by Kyle McAlpine on 18/05/2016.
//
//

import UIKit

public enum ConfettiType {
case Confetti
case Triangle
case Star
case Diamond
case Image(UIImage)

var image: UIImage? {
var imageName: String!

switch self {
case .Confetti:
imageName = "confetti"
case .Triangle:
imageName = "triangle"
case .Star:
imageName = "star"
case .Diamond:
imageName = "diamond"
case let .Image(customImage):
return customImage
}

return UIImage(named: imageName)
}
}
68 changes: 68 additions & 0 deletions Pod/Classes/ConfettiView.swift
@@ -0,0 +1,68 @@
//
// ConfettiView.swift
// Pods
//
// Created by Sudeep Agarwal on 12/14/15.
//
//

import UIKit
import QuartzCore

public class ConfettiView: UIView {
let emitter = CAEmitterLayer()
public var 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),
UIColor(red:0.48, green:0.78, blue:0.64, alpha:1.0),
UIColor(red:0.30, green:0.76, blue:0.85, alpha:1.0),
UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)]
public var intensity: Float = 0.5
public var type: ConfettiType!
private(set) var active = false

public override func layoutSubviews() {
super.layoutSubviews()
emitter.emitterPosition = CGPoint(x: frame.size.width / 2.0, y: 0)
emitter.emitterShape = kCAEmitterLayerLine
emitter.emitterSize = CGSize(width: frame.size.width, height: 1)
}

public func startConfetti() {
guard !active else { return }

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

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

public func stopConfetti() {
guard active else { return }

emitter.birthRate = 0
active = false
}

func confettiWithColor(color: UIColor) -> CAEmitterCell {
let confetti = CAEmitterCell()
confetti.birthRate = 6.0 * intensity
confetti.lifetime = 14.0 * intensity
confetti.lifetimeRange = 0
confetti.color = color.CGColor
confetti.velocity = CGFloat(350.0 * intensity)
confetti.velocityRange = CGFloat(80.0 * intensity)
confetti.emissionLongitude = CGFloat(M_PI)
confetti.emissionRange = CGFloat(M_PI_4)
confetti.spin = CGFloat(3.5 * intensity)
confetti.spinRange = CGFloat(4.0 * intensity)
confetti.scaleRange = CGFloat(intensity)
confetti.scaleSpeed = CGFloat(-0.1 * intensity)
confetti.contents = type.image!.CGImage
return confetti
}
}
120 changes: 0 additions & 120 deletions Pod/Classes/SAConfettiView.swift

This file was deleted.