@@ -22,23 +22,14 @@ public class SwiftLoader: UIView {
2222 private var animated : Bool = true
2323 private var canUpdated = false
2424 private var title : String ?
25- private var speed = 1
2625
2726 private var config : Config = Config ( ) {
2827 didSet {
2928 self . loadingView? . config = config
3029 }
3130 }
3231
33- override public var frame : CGRect {
34- didSet {
35- self . update ( )
36- }
37- }
38-
39- override public func layoutSubviews( ) {
40-
41- super. layoutSubviews ( )
32+ func rotated( notification: NSNotification ) {
4233
4334 let loader = SwiftLoader . sharedInstance
4435
@@ -49,27 +40,28 @@ public class SwiftLoader: UIView {
4940 loader. center = center
5041 loader. coverView? . frame = UIScreen . mainScreen ( ) . bounds
5142 }
52-
43+
44+ override public var frame : CGRect {
45+ didSet {
46+ self . update ( )
47+ }
48+ }
49+
5350 class var sharedInstance : SwiftLoader {
5451 struct Singleton {
5552 static let instance = SwiftLoader ( frame: CGRectMake ( 0 , 0 , Config ( ) . size, Config ( ) . size) )
5653 }
5754 return Singleton . instance
5855 }
5956
60- public class func show( animated: Bool ) {
61- self . show ( nil , animated: animated, topMargin : 0 )
57+ public class func show( animated animated : Bool ) {
58+ self . show ( title : nil , animated: animated)
6259 }
6360
64- public class func show( animated: Bool , topMargin: Int ) {
65- self . show ( nil , animated: animated, topMargin: topMargin)
66- }
67-
68- public class func show( title: String ? , animated: Bool ) {
69- self . show ( title, animated: animated, topMargin: 0 )
70- }
71-
72- public class func show( title: String ? , animated: Bool , topMargin: Int ) {
61+ public class func show( title title: String ? , animated : Bool ) {
62+
63+
64+
7365 let currentWindow : UIWindow = UIApplication . sharedApplication ( ) . keyWindow!
7466
7567 let loader = SwiftLoader . sharedInstance
@@ -78,9 +70,14 @@ public class SwiftLoader: UIView {
7870 loader. title = title
7971 loader. update ( )
8072
73+ NSNotificationCenter . defaultCenter ( ) . addObserver ( loader, selector: #selector( loader. rotated ( _: ) ) ,
74+ name: UIDeviceOrientationDidChangeNotification,
75+ object: nil )
76+
8177 let height : CGFloat = UIScreen . mainScreen ( ) . bounds. size. height
8278 let width : CGFloat = UIScreen . mainScreen ( ) . bounds. size. width
83- let center : CGPoint = CGPointMake ( width / 2.0 , height / 2.0 - CGFloat( topMargin) )
79+ let center : CGPoint = CGPointMake ( width / 2.0 , height / 2.0 )
80+
8481 loader. center = center
8582
8683 if ( loader. superview == nil ) {
@@ -94,19 +91,22 @@ public class SwiftLoader: UIView {
9491 }
9592
9693 public class func hide( ) {
94+
9795 let loader = SwiftLoader . sharedInstance
96+ NSNotificationCenter . defaultCenter ( ) . removeObserver ( loader)
97+
9898 loader. stop ( )
9999 }
100100
101101 public class func setConfig( config : Config ) {
102102 let loader = SwiftLoader . sharedInstance
103103 loader. config = config
104- loader. frame = CGRectMake ( 0 , 0 , loader. config. size, loader. config. size)
104+ loader. frame = CGRectMake ( 0 , 0 , loader. config. size, loader. config. size)
105105 }
106106
107107 /**
108- Private methods
109- */
108+ Private methods
109+ */
110110
111111 private func setup( ) {
112112 self . alpha = 0
@@ -194,11 +194,10 @@ public class SwiftLoader: UIView {
194194 }
195195
196196 /**
197- * Loader View
198- */
197+ * Loader View
198+ */
199199 class SwiftLoadingView : UIView {
200200
201- private var speed : Int ?
202201 private var lineWidth : Float ?
203202 private var lineTintColor : UIColor ?
204203 private var backgroundLayer : CAShapeLayer ?
@@ -220,8 +219,8 @@ public class SwiftLoader: UIView {
220219 }
221220
222221 /**
223- Setup loading view
224- */
222+ Setup loading view
223+ */
225224
226225 private func setup( ) {
227226 self . backgroundColor = UIColor . clearColor ( )
@@ -237,15 +236,14 @@ public class SwiftLoader: UIView {
237236
238237 private func update( ) {
239238 self . lineWidth = self . config. spinnerLineWidth
240- self . speed = self . config. speed
241239
242240 self . backgroundLayer? . lineWidth = CGFloat ( self . lineWidth!)
243241 self . backgroundLayer? . strokeColor = self . config. spinnerColor. CGColor
244242 }
245243
246244 /**
247- Draw Circle
248- */
245+ Draw Circle
246+ */
249247
250248 override func drawRect( rect: CGRect ) {
251249 self . backgroundLayer? . frame = self . bounds
@@ -270,16 +268,16 @@ public class SwiftLoader: UIView {
270268 }
271269
272270 /**
273- Start and stop spinning
274- */
271+ Start and stop spinning
272+ */
275273
276274 private func start( ) {
277275 self . isSpinning? = true
278276 self . drawBackgroundCircle ( true )
279277
280278 let rotationAnimation : CABasicAnimation = CABasicAnimation ( keyPath: " transform.rotation.z " )
281279 rotationAnimation. toValue = NSNumber ( double: M_PI * 2.0 )
282- rotationAnimation. duration = CFTimeInterval ( speed! ) ;
280+ rotationAnimation. duration = 1 ;
283281 rotationAnimation. cumulative = true ;
284282 rotationAnimation. repeatCount = HUGE;
285283 self . backgroundLayer? . addAnimation ( rotationAnimation, forKey: " rotationAnimation " )
@@ -295,61 +293,57 @@ public class SwiftLoader: UIView {
295293
296294
297295 /**
298- * Loader config
299- */
296+ * Loader config
297+ */
300298 public struct Config {
301299
302300 /**
303- * Size of loader
304- */
301+ * Size of loader
302+ */
305303 public var size : CGFloat = 120.0
306304
307305 /**
308- * Color of spinner view
309- */
306+ * Color of spinner view
307+ */
310308 public var spinnerColor = UIColor . blackColor ( )
311309
312310 /**
313- * Spinner Line Width
311+ * S
314312 */
315313 public var spinnerLineWidth : Float = 1.0
316314
317315 /**
318- * Color of title text
319- */
320- public var titleTextColor = UIColor . blackColor ( )
321-
322- /**
323- * Speed of the spinner
316+ * Color of title text
324317 */
325- public var speed : Int = 1
318+ public var titleTextColor = UIColor . blackColor ( )
326319
327320 /**
328- * Font for title text in loader
329- */
321+ * Font for title text in loader
322+ */
330323 public var titleTextFont : UIFont = UIFont . boldSystemFontOfSize ( 16.0 )
331324
332325 /**
333- * Background color for loader
334- */
326+ * Background color for loader
327+ */
335328 public var backgroundColor = UIColor . whiteColor ( )
336329
337330 /**
338- * Foreground color
339- */
331+ * Foreground color
332+ */
340333 public var foregroundColor = UIColor . clearColor ( )
341334
342335 /**
343- * Foreground alpha CGFloat, between 0.0 and 1.0
344- */
336+ * Foreground alpha CGFloat, between 0.0 and 1.0
337+ */
345338 public var foregroundAlpha : CGFloat = 0.0
346339
347340 /**
348- * Corner radius for loader
349- */
341+ * Corner radius for loader
342+ */
350343 public var cornerRadius : CGFloat = 10.0
351344
352345 public init ( ) { }
353346
354347 }
355348}
349+
0 commit comments