Skip to content

Commit 48d8dc6

Browse files
Add clockwise rotation property
1 parent 911f115 commit 48d8dc6

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Example/ParticlesLoadingView/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ViewController: UIViewController {
2222
view.particleEffect = .Laser
2323
view.duration = 1.5
2424
view.particlesSize = 15.0
25+
view.clockwiseRotation = true
2526
view.layer.borderColor = UIColor.lightGrayColor().CGColor
2627
view.layer.borderWidth = 1.0
2728
view.layer.cornerRadius = 15.0

Pod/Classes/ParticlesLoadingView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class ParticlesLoadingView: UIView {
2626
}
2727
}
2828

29+
/// Default value is false so the animation is counter-clockwise. Set this property to true to make the animation go clockwise.
30+
public var clockwiseRotation: Bool = false
31+
2932
/// SKScene subclass that is responsible for the emission of particles.
3033
private var scene: ParticlesScene!
3134

Pod/Classes/ParticlesScene.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ public class ParticlesScene: SKScene {
7676
let verticalTranslationFactor = 2 / (1 - verticalInsetScaleFactor)
7777
border.applyTransform(CGAffineTransformMakeScale(horizontalInsetScaleFactor, verticalInsetScaleFactor))
7878
border.applyTransform(CGAffineTransformMakeTranslation(scene.frame.size.width / horizontalTranslationFactor, scene.frame.size.height / verticalTranslationFactor))
79-
let followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration)
79+
var followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration)
80+
if let superview = view?.superview as? ParticlesLoadingView {
81+
if superview.clockwiseRotation {
82+
followLine = followLine.reversedAction()
83+
}
84+
}
8085
loopAction = SKAction.repeatActionForever(followLine)
8186
}
8287
}

0 commit comments

Comments
 (0)