Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

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

6 changes: 6 additions & 0 deletions Example/SAConfettiView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -494,6 +496,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -506,6 +509,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -525,6 +529,7 @@
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SAConfettiView_Example.app/SAConfettiView_Example";
};
name = Debug;
Expand All @@ -541,6 +546,7 @@
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SAConfettiView_Example.app/SAConfettiView_Example";
};
name = Release;
Expand Down
12 changes: 6 additions & 6 deletions Example/SAConfettiView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
6 changes: 3 additions & 3 deletions Example/SAConfettiView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ViewController: UIViewController {
var isRainingConfetti = false
@IBOutlet var confettiStatus: UILabel!

override func prefersStatusBarHidden() -> Bool {
override var prefersStatusBarHidden : Bool {
return true
}

Expand All @@ -36,7 +36,7 @@ class ViewController: UIViewController {
confettiView.intensity = 0.5

// Set type
confettiView.type = .Diamond
confettiView.type = .diamond

// For custom image
// confettiView.type = .Image(UIImage(named: "diamond")!)
Expand All @@ -45,7 +45,7 @@ class ViewController: UIViewController {
view.addSubview(confettiView)
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if (isRainingConfetti) {
// Stop confetti
confettiView.stopConfetti()
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Tests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down
60 changes: 30 additions & 30 deletions Pod/Classes/SAConfettiView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import UIKit
import QuartzCore

public class SAConfettiView: UIView {
open class SAConfettiView: UIView {

public enum ConfettiType {
case Confetti
case Triangle
case Star
case Diamond
case Image(UIImage)
case confetti
case triangle
case star
case diamond
case image(UIImage)
}

var emitter: CAEmitterLayer!
public var colors: [UIColor]!
public var intensity: Float!
public var type: ConfettiType!
private var active :Bool!
open var colors: [UIColor]!
open var intensity: Float!
open var type: ConfettiType!
fileprivate var active :Bool!

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -42,11 +42,11 @@ public class SAConfettiView: UIView {
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)]
intensity = 0.5
type = .Confetti
type = .confetti
active = false
}

public func startConfetti() {
open func startConfetti() {
emitter = CAEmitterLayer()

emitter.emitterPosition = CGPoint(x: frame.size.width / 2.0, y: 0)
Expand All @@ -63,58 +63,58 @@ public class SAConfettiView: UIView {
active = true
}

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

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

var fileName: String!

switch type {
case .Confetti:
case .confetti:
fileName = "confetti"
case .Triangle:
case .triangle:
fileName = "triangle"
case .Star:
case .star:
fileName = "star"
case .Diamond:
case .diamond:
fileName = "diamond"
case let .Image(customImage):
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")
let url = NSURL(fileURLWithPath: imagePath!)
let data = NSData(contentsOfURL: url)
let path = Bundle(for: SAConfettiView.self).path(forResource: "SAConfettiView", ofType: "bundle")
let bundle = Bundle(path: path!)
let imagePath = bundle?.path(forResource: fileName, ofType: "png")
let url = URL(fileURLWithPath: imagePath!)
let data = try? Data(contentsOf: url)
if let data = data {
return UIImage(data: data)!
}
return nil
}

func confettiWithColor(color: UIColor) -> CAEmitterCell {
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.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.emissionLongitude = CGFloat(Double.pi)
confetti.emissionRange = CGFloat(Double.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 = imageForType(type)!.CGImage
confetti.contents = imageForType(type)!.cgImage
return confetti
}

public func isActive() -> Bool {
open func isActive() -> Bool {
return self.active
}
}
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SAConfettiView is available through [CocoaPods](http://cocoapods.org). To instal
it, simply add the following line to your Podfile:

```swift
pod "SAConfettiView"
pod 'SAConfettiView', :git => 'https://github.com/gokhanakkurt/SAConfettiView.git', :branch => 'swift3'
```

And then run:
Expand All @@ -44,54 +44,54 @@ self.view.addSubview(confettiView)

### Types

Pick one of the preconfigured types of confetti with the `.type` property, or create your own by providing a custom image. This property defaults to the `.Confetti` type.
Pick one of the preconfigured types of confetti with the `.type` property, or create your own by providing a custom image. This property defaults to the `.confetti` type.

##### `.Confetti`
##### `.confetti`

![confetti](https://cloud.githubusercontent.com/assets/11940172/11819440/c9db329e-a39a-11e5-9284-b0171bee0f24.gif)

```swift
confettiView.type = .Confetti
confettiView.type = .confetti
```

##### `.Triangle`
##### `.triangle`

![triangle](https://cloud.githubusercontent.com/assets/11940172/11819211/9b8b758a-a399-11e5-8ed3-2eb92f633628.gif)

```swift
confettiView.type = .Triangle
confettiView.type = .triangle
```

##### `.Star`
##### `.star`

![star](https://cloud.githubusercontent.com/assets/11940172/11819401/90a2188a-a39a-11e5-8a03-ddca3fb52e72.gif)

```swift
confettiView.type = .Star
confettiView.type = .star
```

##### `.Diamond`
##### `.diamond`

![diamond](https://cloud.githubusercontent.com/assets/11940172/11819275/f1c83c08-a399-11e5-8d40-85e9a1879526.gif)

```swift
confettiView.type = .Diamond
confettiView.type = .diamond
```

##### `.Image`
##### `.image`

![image](https://cloud.githubusercontent.com/assets/11940172/11819363/5f4f0dba-a39a-11e5-826b-d198113f50dd.gif)

```swift
confettiView.type = .Image(UIImage(named: "smiley"))
confettiView.type = .image(UIImage(named: "smiley"))
```

### Colors

Set the colors of the confetti with the `.colors` property. This property has a default value of multiple colors.
Set the colors of the confetti with the `.colors` property. This property has a default value of multiple colors.

``` swift
confettiView.colors = [UIColor.redColor(), UIColor.greenColor(), UIColor.blueColor()]
confettiView.colors = [UIColor.red, UIColor.green, UIColor.blue]
```

### Intensity
Expand Down