From 48d8dc673cf1a83aa97011fd2df889f3fb5905ba Mon Sep 17 00:00:00 2001 From: Patrick Balestra Date: Tue, 24 May 2016 21:10:43 +0200 Subject: [PATCH] Add clockwise rotation property --- Example/ParticlesLoadingView/ViewController.swift | 1 + Pod/Classes/ParticlesLoadingView.swift | 3 +++ Pod/Classes/ParticlesScene.swift | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Example/ParticlesLoadingView/ViewController.swift b/Example/ParticlesLoadingView/ViewController.swift index d6b4214..0632f3a 100644 --- a/Example/ParticlesLoadingView/ViewController.swift +++ b/Example/ParticlesLoadingView/ViewController.swift @@ -22,6 +22,7 @@ class ViewController: UIViewController { view.particleEffect = .Laser view.duration = 1.5 view.particlesSize = 15.0 + view.clockwiseRotation = true view.layer.borderColor = UIColor.lightGrayColor().CGColor view.layer.borderWidth = 1.0 view.layer.cornerRadius = 15.0 diff --git a/Pod/Classes/ParticlesLoadingView.swift b/Pod/Classes/ParticlesLoadingView.swift index cdfbbf6..25e6dbb 100644 --- a/Pod/Classes/ParticlesLoadingView.swift +++ b/Pod/Classes/ParticlesLoadingView.swift @@ -26,6 +26,9 @@ public class ParticlesLoadingView: UIView { } } + /// Default value is false so the animation is counter-clockwise. Set this property to true to make the animation go clockwise. + public var clockwiseRotation: Bool = false + /// SKScene subclass that is responsible for the emission of particles. private var scene: ParticlesScene! diff --git a/Pod/Classes/ParticlesScene.swift b/Pod/Classes/ParticlesScene.swift index 43710bb..ab12df9 100644 --- a/Pod/Classes/ParticlesScene.swift +++ b/Pod/Classes/ParticlesScene.swift @@ -76,7 +76,12 @@ public class ParticlesScene: SKScene { let verticalTranslationFactor = 2 / (1 - verticalInsetScaleFactor) border.applyTransform(CGAffineTransformMakeScale(horizontalInsetScaleFactor, verticalInsetScaleFactor)) border.applyTransform(CGAffineTransformMakeTranslation(scene.frame.size.width / horizontalTranslationFactor, scene.frame.size.height / verticalTranslationFactor)) - let followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration) + var followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration) + if let superview = view?.superview as? ParticlesLoadingView { + if superview.clockwiseRotation { + followLine = followLine.reversedAction() + } + } loopAction = SKAction.repeatActionForever(followLine) } }