Skip to content

Commit

Permalink
Merge branch 'swift3.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Example/ParticlesLoadingView.xcodeproj/project.pbxproj
#	Example/Pods/Pods.xcodeproj/project.pbxproj
  • Loading branch information
BalestraPatrick committed Oct 1, 2016
2 parents b6694ac + 939cdf4 commit 2a2dbe5
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 63 deletions.
9 changes: 4 additions & 5 deletions Example/ParticlesLoadingView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -326,7 +327,6 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand Down Expand Up @@ -365,8 +365,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -394,7 +392,7 @@
PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-ParticlesLoadingView_Example";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = ParticlesLoadingView_Example;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -421,7 +419,8 @@
PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-ParticlesLoadingView_Example";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = ParticlesLoadingView_Example;
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
14 changes: 6 additions & 8 deletions Example/ParticlesLoadingView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
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
24 changes: 12 additions & 12 deletions Example/ParticlesLoadingView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ViewController: UIViewController {
@IBOutlet weak var messageView: UIView!

lazy var loadingView: ParticlesLoadingView = {
let x = UIScreen.mainScreen().bounds.size.width / 2 - (75 / 2) - 200 // 🙈
let y = UIScreen.mainScreen().bounds.size.height / 2 - (75 / 2) // 🙉
let x = UIScreen.main.bounds.size.width / 2 - (75 / 2) - 200 // 🙈
let y = UIScreen.main.bounds.size.height / 2 - (75 / 2) // 🙉
let view = ParticlesLoadingView(frame: CGRect(x: x, y: y, width: 75, height: 75))
view.particleEffect = .Laser
view.particleEffect = .laser
view.duration = 1.5
view.particlesSize = 15.0
view.clockwiseRotation = true
view.layer.borderColor = UIColor.lightGrayColor().CGColor
view.layer.borderColor = UIColor.lightGray.cgColor
view.layer.borderWidth = 1.0
view.layer.cornerRadius = 15.0
return view
Expand All @@ -38,32 +38,32 @@ class ViewController: UIViewController {

// Customize view, choose the Fire effect and start the animation.
messageView.layer.cornerRadius = 15.0
messageView.layer.borderColor = UIColor.lightGrayColor().CGColor
messageView.layer.borderColor = UIColor.lightGray.cgColor
messageView.layer.borderWidth = 1.0
messageView.addParticlesAnimation(effect: ParticleEffect.Fire)
messageView.addParticlesAnimation(effect: ParticleEffect.fire)
messageView.startAnimating()

// Use a custom emitter particles file and customize the view.
if let emitter = NSKeyedUnarchiver.unarchiveObjectWithFile(NSBundle.mainBundle().pathForResource("Spark", ofType: "sks")!) as? SKEmitterNode {
if let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: Bundle.main.path(forResource: "Spark", ofType: "sks")!) as? SKEmitterNode {
circleLoadingView.layer.borderWidth = 1.0
circleLoadingView.layer.borderColor = UIColor.lightGrayColor().CGColor
circleLoadingView.layer.borderColor = UIColor.lightGray.cgColor
circleLoadingView.layer.cornerRadius = circleLoadingView.frame.size.width / 2
circleLoadingView.addParticlesAnimation(emitter)
circleLoadingView.addParticlesAnimation(with: emitter)
circleLoadingView.startAnimating()
}
}

@IBAction func controlAnimation(sender: UIButton) {
@IBAction func controlAnimation(_ sender: UIButton) {
if circleLoadingView.isEmitting() {
circleLoadingView.stopAnimating()
loadingView.stopAnimating()
messageView.stopAnimating()
sender.setTitle("Start Animating", forState: .Normal)
sender.setTitle("Start Animating", for: UIControlState())
} else {
circleLoadingView.startAnimating()
loadingView.startAnimating()
messageView.startAnimating()
sender.setTitle("Stop Animating", forState: .Normal)
sender.setTitle("Stop Animating", for: UIControlState())
}
}
}
Expand Down
11 changes: 7 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.

14 changes: 7 additions & 7 deletions Pod/Classes/EmitterCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import SpriteKit

public class EmitterCreator {

public enum EmitterError: ErrorType {
case EmitterNodeUnavailable
public enum EmitterError: Error {
case emitterNodeUnavailable
}

/// Creates a SKEmitterNode from one of the predefined particle emitter files.
///
/// - throws: An error if the file could not be found.
///
/// - returns: The emitter node object.
func createEmitterNode(effect: ParticleEffect) throws -> SKEmitterNode {
let bundle = NSBundle(forClass: self.dynamicType)
func createEmitterNode(with effect: ParticleEffect) throws -> SKEmitterNode {
let bundle = Bundle(for: type(of: self))
let bundleName = bundle.infoDictionary!["CFBundleName"] as! String
let path = NSBundle(forClass: self.dynamicType).pathForResource(effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle")
if let path = path, let emitter = NSKeyedUnarchiver.unarchiveObjectWithFile(path) as? SKEmitterNode, let texture = UIImage(named: "\(bundleName).bundle/spark", inBundle: bundle, compatibleWithTraitCollection: nil) {
let path = Bundle(for: type(of: self)).path(forResource: effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle")
if let path = path, let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: path) as? SKEmitterNode, let texture = UIImage(named: "\(bundleName).bundle/spark", in: bundle, compatibleWith: nil) {
emitter.particleTexture = SKTexture(image: texture)
return emitter
} else {
throw EmitterError.EmitterNodeUnavailable
throw EmitterError.emitterNodeUnavailable
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Pod/Classes/ParticleEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Foundation

public enum ParticleEffect: String {
case Laser = "Laser"
case Spark = "Spark"
case Bokeh = "Bokeh"
case Fire = "Fire"
}
case laser = "Laser"
case spark = "Spark"
case bokeh = "Bokeh"
case fire = "Fire"
}
12 changes: 6 additions & 6 deletions Pod/Classes/ParticlesLoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public class ParticlesLoadingView: UIView {
private let emitterCreator = EmitterCreator()

/// The particle effect used to emit particles.
public var particleEffect = ParticleEffect.Laser {
public var particleEffect = ParticleEffect.laser {
didSet {
if let _ = scene {
do {
let emitter = try emitterCreator.createEmitterNode(particleEffect)
let emitter = try emitterCreator.createEmitterNode(with: particleEffect)
scene.setEmitterNode(emitter)
} catch {
fatalError("Could not find the particles file")
Expand All @@ -59,20 +59,20 @@ public class ParticlesLoadingView: UIView {
override public init(frame: CGRect) {
super.init(frame: frame)
spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
spriteKitView.backgroundColor = UIColor.clearColor()
spriteKitView.backgroundColor = UIColor.clear
setUp()
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
spriteKitView.backgroundColor = UIColor.clearColor()
spriteKitView.backgroundColor = UIColor.clear
setUp()
}

func setUp() {
do {
let emitter = try emitterCreator.createEmitterNode(particleEffect)
let emitter = try emitterCreator.createEmitterNode(with: particleEffect)
scene = ParticlesScene(size: frame.size, emitterNode: emitter)
spriteKitView.presentScene(scene)
addSubview(spriteKitView)
Expand All @@ -97,7 +97,7 @@ public class ParticlesLoadingView: UIView {
}

// UIView automatically invoke this function when a view adds me as a subview. It is used to get the border path of the view.
public override func willMoveToSuperview(newSuperview: UIView?) {
public override func willMove(toSuperview newSuperview: UIView?) {
scene.setAnimationPath()
}

Expand Down
26 changes: 13 additions & 13 deletions Pod/Classes/ParticlesScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ParticlesScene: SKScene {
/// Main emitter node: modify its properties as you wish.
private var emitterNode: SKEmitterNode = SKEmitterNode() {
didSet {
emitterNode.position = CGPointZero
emitterNode.position = CGPoint.zero
}
}

Expand All @@ -25,9 +25,9 @@ public class ParticlesScene: SKScene {

public init(size: CGSize, emitterNode: SKEmitterNode) {
self.emitterNode = emitterNode
self.emitterNode.position = CGPointMake(10, 0)
self.emitterNode.position = CGPoint(x: 10, y: 0)
super.init(size: size)
backgroundColor = UIColor.clearColor()
backgroundColor = UIColor.clear
}

required public init?(coder aDecoder: NSCoder) {
Expand All @@ -36,15 +36,15 @@ public class ParticlesScene: SKScene {
/// Set a new emitter node as the source of the particles.
///
/// - parameter emitter: The object that will emit the particles.
public func setEmitterNode(emitter: SKEmitterNode) {
public func setEmitterNode(_ emitter: SKEmitterNode) {
self.emitterNode = emitter
}

/// Start animating the emitter node with the default values.
func startAnimating() {
emitterNode.particleBirthRate = 5000.0
emitterNode.targetNode = scene
emitterNode.runAction(loopAction, withKey: "loop")
emitterNode.run(loopAction, withKey: "loop")
if emitterNode.parent == nil {
addChild(emitterNode)
}
Expand All @@ -62,29 +62,29 @@ public class ParticlesScene: SKScene {

/// Figure out the border path of the view and set it as the path of the animation.
func setAnimationPath() {
var radii = CGSizeZero
var radii = CGSize.zero
if let radius = view?.superview?.layer.cornerRadius {
radii = CGSize(width: radius, height: radius)
}
let duration = (view?.superview as? ParticlesLoadingView)?.duration ?? 1.5
let particlesSize = (view?.superview as? ParticlesLoadingView)?.particlesSize ?? 5.0
if let scene = scene {
let border = UIBezierPath(roundedRect: scene.frame, byRoundingCorners: .AllCorners, cornerRadii: radii)
let border = UIBezierPath(roundedRect: scene.frame, byRoundingCorners: .allCorners, cornerRadii: radii)
let horizontalInsetScaleFactor: CGFloat = 1 - (particlesSize / scene.frame.size.width)
let verticalInsetScaleFactor: CGFloat = 1 - (particlesSize / scene.frame.size.height)
let horizontalTranslationFactor = 2 / (1 - horizontalInsetScaleFactor)
let verticalTranslationFactor = 2 / (1 - verticalInsetScaleFactor)
border.applyTransform(CGAffineTransformMakeScale(horizontalInsetScaleFactor, verticalInsetScaleFactor))
border.applyTransform(CGAffineTransformMakeTranslation(scene.frame.size.width / horizontalTranslationFactor, scene.frame.size.height / verticalTranslationFactor))
var followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration)
border.apply(CGAffineTransform(scaleX: horizontalInsetScaleFactor, y: verticalInsetScaleFactor))
border.apply(CGAffineTransform(translationX: scene.frame.size.width / horizontalTranslationFactor, y: scene.frame.size.height / verticalTranslationFactor))
var followLine = SKAction.follow(border.cgPath, asOffset: false, orientToPath: true, duration: duration)
if let superview = view?.superview as? ParticlesLoadingView {
if superview.clockwiseRotation {
followLine = followLine.reversedAction()
followLine = followLine.reversed()
}
}
loopAction = SKAction.repeatActionForever(followLine)
loopAction = SKAction.repeatForever(followLine)
}
}
}



6 changes: 3 additions & 3 deletions Pod/Classes/UIView+ParticlesAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public extension UIView {
/// Add a particles animation with a SKEmitterNode.
///
/// - parameter emitter: Emitter node object.
public func addParticlesAnimation(emitter: SKEmitterNode? = nil, effect: ParticleEffect? = nil) {
public func addParticlesAnimation(with emitter: SKEmitterNode? = nil, effect: ParticleEffect? = nil) {
var spriteKitView = SKView()
spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
spriteKitView.backgroundColor = UIColor.clearColor()
spriteKitView.backgroundColor = UIColor.clear

var scene: ParticlesScene
if let emitter = emitter {
scene = ParticlesScene(size: frame.size, emitterNode: emitter)
} else if let effect = effect {
do {
let emitter = try EmitterCreator().createEmitterNode(effect)
let emitter = try EmitterCreator().createEmitterNode(with: effect)
scene = ParticlesScene(size: frame.size, emitterNode: emitter)
} catch {
fatalError("The default ParticleEffect could not be loaded.")
Expand Down

0 comments on commit 2a2dbe5

Please sign in to comment.