Skip to content

Commit 8bdf82e

Browse files
Ketan ChopdaKetan Chopda
authored andcommitted
- Dynamic spinner enhancement
- Ball clip rotate - Line spin fade - Circle stroke pin
1 parent a58cee5 commit 8bdf82e

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

SSSpinnerButton.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
);
222222
runOnlyForDeploymentPostprocessing = 0;
223223
shellPath = /bin/sh;
224-
shellScript = "if hash tailor 2>/dev/null; then\ntailor\nelse\necho \"warning: Please install Tailor from https://tailor.sh\"\nfi\n";
224+
shellScript = "if hash tailor 2>/dev/null; then\ntailor\nelse\necho \"warning: Please install Tailor from https://tailor.sh\"\nfi";
225225
};
226226
/* End PBXShellScriptBuildPhase section */
227227

SSSpinnerButton/SSSpinnerButton/SpinerShapes/SpinnerShapeWithAnimation/SSBallRotateChase.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ class SSBallRotateChase: SSSpinnerAnimationDelegate {
2020
func setupSpinnerAnimation(layer: CALayer, frame: CGRect, color: UIColor, spinnerSize: UInt?) {
2121

2222
var defaultPadding: CGFloat = 10.0
23-
2423
var sizeofSpinner: CGFloat?
2524
if spinnerSize != nil {
2625
defaultPadding = 0.0
2726
sizeofSpinner = max(CGFloat(spinnerSize!) - defaultPadding, 1.0)
2827
}
29-
3028
var size = max(min(frame.width, frame.height) - defaultPadding, 1.0)
31-
32-
if sizeofSpinner != nil && sizeofSpinner! > (size - 10) {
29+
if sizeofSpinner != nil && sizeofSpinner! > (size - defaultPadding) {
3330
defaultPadding = 10.0
3431
size = max(min(frame.width, frame.height) - defaultPadding, 1.0)
3532
sizeofSpinner = size

SSSpinnerButton/SSSpinnerButton/SpinerShapes/SpinnerShapeWithAnimation/SSBallSpinFadeLoader.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SSBallSpinFadeLoader: SSSpinnerAnimationDelegate {
2626
if spinnerSize != nil {
2727
sizeOfSpinner = max(min(CGFloat(spinnerSize!), sizeOfSpinner), 1.0)
2828
}
29-
let center = CGPoint(x: (sizeValue/2), y: (sizeValue/2))
29+
let center = CGPoint(x: (sizeValue / 2), y: (sizeValue / 2))
3030
let circleSpacing: CGFloat = 1
3131
let circleSize = max((sizeOfSpinner * circleSpacing / 8), 1.0)
3232

@@ -82,7 +82,7 @@ class SSBallSpinFadeLoader: SSSpinnerAnimationDelegate {
8282
/// - color: spinner color
8383
/// - Returns:
8484
func circleAt(angle: CGFloat, size: CGFloat, origin: CGPoint, containerSize: CGSize, color: UIColor) -> CALayer {
85-
let radius = (containerSize.width/2) - (size/2)
85+
let radius = (containerSize.width / 2) - (size / 2)
8686
let circle = SpinnerShape.circle.layerWith(size: CGSize(width: size, height: size), color: color)
8787
let frame = CGRect(
8888
x: origin.x + radius * (cos(angle)) - (size / 2),
@@ -92,7 +92,6 @@ class SSBallSpinFadeLoader: SSSpinnerAnimationDelegate {
9292

9393
circle.frame = frame
9494

95-
9695
return circle
9796
}
9897

SSSpinnerButton/SSSpinnerButton/SpinerShapes/SpinnerShapeWithAnimation/SSCircleStrokeSpin.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ class SSCircleStrokeSpin: SSSpinnerAnimationDelegate {
2121
func setupSpinnerAnimation(layer: CALayer, frame: CGRect, color: UIColor, spinnerSize: UInt?) {
2222

2323
let defaultPadding: CGFloat = 10.0
24+
var center = CGPoint(x: defaultPadding / 2, y: defaultPadding / 2)
2425
var sizeValue = max(min(frame.width, frame.height) - defaultPadding, 1.0)
25-
if spinnerSize != nil {
26-
sizeValue = max(CGFloat(spinnerSize!) - defaultPadding, 1.0)
26+
if spinnerSize != nil && CGFloat(spinnerSize!) < sizeValue {
27+
sizeValue = max(CGFloat(spinnerSize!), 1.0)
28+
center = CGPoint(x: frame.height / 2 - sizeValue / 2, y: frame.height / 2 - sizeValue / 2)
2729
}
2830
let beginTime: Double = 0.5
2931
let strokeStartDuration: Double = 1.2
@@ -55,8 +57,8 @@ class SSCircleStrokeSpin: SSSpinnerAnimationDelegate {
5557

5658
let circle = SpinnerShape.stroke.layerWith(size: CGSize(width: sizeValue, height: sizeValue), color: color)
5759
let frame = CGRect(
58-
x: defaultPadding / 2,
59-
y: defaultPadding / 2,
60+
x: center.x,
61+
y: center.y,
6062
width: sizeValue,
6163
height: sizeValue
6264
)

SSSpinnerButton/SSSpinnerButton/SpinerShapes/SpinnerShapeWithAnimation/SSLineSpinFadeLoader.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class SSLineSpinFadeLoader: SSSpinnerAnimationDelegate {
2323
let defaultPadding: CGFloat = 4.0
2424

2525
var sizeValue = max(min(frame.width, frame.height) - defaultPadding, 1.0)
26-
if spinnerSize != nil {
27-
sizeValue = max(CGFloat(spinnerSize!) - defaultPadding, 1.0)
26+
var center = CGPoint(x: (sizeValue / 2) + (defaultPadding / 2), y: (sizeValue/2) + (defaultPadding / 2))
27+
if spinnerSize != nil && CGFloat(spinnerSize!) < sizeValue {
28+
sizeValue = max(CGFloat(spinnerSize!), 1.0)
29+
center = CGPoint(x: frame.height / 2, y: frame.height / 2)
2830
}
29-
let center = CGPoint(x: (sizeValue/2) + (defaultPadding / 2), y: (sizeValue/2) + (defaultPadding / 2))
3031
let duration: CFTimeInterval = 1.2
3132
let beginTime = CACurrentMediaTime()
3233
let beginTimes: [CFTimeInterval] = [0.12, 0.24, 0.36, 0.48, 0.6, 0.72, 0.84, 0.96]

SSSpinnerButton/SSSpinnerButton/SpinerShapes/SpinnerShapeWithAnimation/SSSpinnerBallClipRotate.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import UIKit
1212
///
1313
class SSSpinnerBallClipRotate: SSSpinnerAnimationDelegate {
1414

15-
16-
1715
/// setup spinner layer
1816
///
1917
/// - Parameters:
@@ -23,11 +21,15 @@ class SSSpinnerBallClipRotate: SSSpinnerAnimationDelegate {
2321
func setupSpinnerAnimation(layer: CALayer, frame: CGRect, color: UIColor, spinnerSize: UInt?) {
2422

2523
var sizeValue = min(frame.width, frame.height)
26-
if spinnerSize != nil {
24+
var center = CGPoint(x: 0, y: 0)
25+
if spinnerSize != nil && CGFloat(spinnerSize!) < sizeValue {
2726
sizeValue = max(CGFloat(spinnerSize!), 1.0)
27+
center = CGPoint(x: frame.height / 2 - sizeValue / 2, y: frame.height / 2 - sizeValue / 2)
2828
}
2929
let ballClip = SpinnerShape.ring.layerWith(size: CGSize(width: sizeValue, height: sizeValue), color: color)
30-
ballClip.frame = CGRect(x: 0, y: 0, width: sizeValue, height: sizeValue)
30+
ballClip.frame = CGRect(x: center.x, y: center.x, width: sizeValue, height: sizeValue)
31+
ballClip.frame.size.height = sizeValue
32+
ballClip.frame.size.width = sizeValue
3133

3234
layer.addSublayer(ballClip)
3335

SSSpinnerButton/SSSpinnerButton/SpinnerButton/SSSpinnerButton.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,14 @@ private extension SSSpinnerButton {
229229
self.setImage(storedHighlightedImage, for: .highlighted)
230230
isUserInteractionEnabled = true
231231

232-
let animaton = CABasicAnimation(keyPath: "bounds.size.width")
233-
234-
animaton.fromValue = frame.height
235-
animaton.toValue = frame.width
236-
animaton.duration = animationDuration
237-
animaton.fillMode = kCAFillModeForwards
238-
animaton.isRemovedOnCompletion = false
239-
240-
layer.add(animaton, forKey: animaton.keyPath)
232+
let animation = CABasicAnimation(keyPath: "bounds.size.width")
233+
animation.fromValue = frame.height
234+
animation.toValue = frame.width
235+
animation.duration = animationDuration
236+
animation.fillMode = kCAFillModeForwards
237+
animation.isRemovedOnCompletion = false
238+
239+
layer.add(animation, forKey: animation.keyPath)
241240
isAnimating = false
242241
self.layer.cornerRadius = self.cornrRadius
243242
if complete != nil {

SSSpinnerButton/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ViewController: UIViewController {
3131

3232
let arr: [SpinnerType] = [.ballClipRotate, .ballSpinFade, .lineSpinFade, .ballRotateChase, .circleStrokeSpin]
3333

34-
sender.startAnimate(spinnerType: arr[sender.tag], spinnercolor: .white, spinnerSize: 15 , complete: nil)
34+
sender.startAnimate(spinnerType: arr[sender.tag], spinnercolor: .white, spinnerSize: 20, complete: nil)
3535
Timer.scheduledTimer(withTimeInterval: 5, repeats: false) { (_) in
3636
sender.stopAnimate(complete: {
3737
})

0 commit comments

Comments
 (0)