@@ -29,12 +29,14 @@ open class HUD: UIView {
29
29
/// Called after the HUD is hidden.
30
30
public var completionBlock : ( ( ) -> Void ) ?
31
31
32
- /// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden. Defaults to 0 (no minimum show time).
32
+ /// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden.
33
+ /// Defaults to 0 (no minimum show time).
33
34
/// - Note: The graceTime needs to be set before the hud is shown. You thus can't use `show(to:animated:)`,
34
35
/// but instead need to alloc / init the HUD, configure the grace time and than show it manually.
35
36
public var graceTime : TimeInterval = 0.0
36
37
37
- /// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden. Defaults to 0 (no minimum show time).
38
+ /// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden.
39
+ /// Defaults to 0 (no minimum show time).
38
40
public var minShowTime : TimeInterval = 0.0
39
41
40
42
/// Removes the HUD from its parent view when hidden. Defaults to true.
@@ -49,7 +51,8 @@ open class HUD: UIView {
49
51
}
50
52
}
51
53
52
- /// A color that gets forwarded to all labels and supported indicators. Also sets the tintColor for custom views. Defaults to semi-translucent black.
54
+ /// A color that gets forwarded to all labels and supported indicators. Also sets the tintColor for custom views.
55
+ /// Defaults to semi-translucent black.
53
56
public var contentColor : UIColor = {
54
57
if #available( iOS 13 . 0 , tvOS 13 . 0 , * ) {
55
58
return UIColor . label. withAlphaComponent ( 0.7 )
@@ -65,7 +68,8 @@ open class HUD: UIView {
65
68
/// The animation type that should be used when the HUD is shown and hidden.
66
69
public var animationType : HUDAnimation = . fade
67
70
68
- /// The bezel offset relative to the center of the view. You can use `HUD.maxOffset` and `-HUD.maxOffset` to move the HUD all the way to the screen edge in each direction.
71
+ /// The bezel offset relative to the center of the view. You can use `HUD.maxOffset` and `-HUD.maxOffset`
72
+ /// to move the HUD all the way to the screen edge in each direction.
69
73
/// E.g., `CGPoint(x: 0.0, y: HUD.maxOffset)` would position the HUD centered on the bottom edge.
70
74
public var offset : CGPoint = . zero {
71
75
didSet {
@@ -144,7 +148,8 @@ open class HUD: UIView {
144
148
}
145
149
}
146
150
147
- /// A label that holds an optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit the entire text.
151
+ /// A label that holds an optional short message to be displayed below the activity indicator.
152
+ /// The HUD is automatically resized to fit the entire text.
148
153
public lazy var label = UILabel ( frame: . zero)
149
154
150
155
/// A label that holds an optional details message displayed below the labelText message. The details text can span multiple lines.
@@ -260,7 +265,8 @@ extension HUD {
260
265
if let showStarted = showStarted, minShowTime > 0.0 {
261
266
let interv = Date ( ) . timeIntervalSince ( showStarted)
262
267
if interv < minShowTime {
263
- let timer = Timer ( timeInterval: minShowTime - interv, target: self , selector: #selector( handleMinShowTimer) , userInfo: nil , repeats: false )
268
+ let timer = Timer ( timeInterval: minShowTime - interv, target: self ,
269
+ selector: #selector( handleMinShowTimer) , userInfo: nil , repeats: false )
264
270
RunLoop . current. add ( timer, forMode: . common)
265
271
minShowTimer = timer
266
272
return
@@ -315,7 +321,7 @@ extension HUD {
315
321
316
322
if animated && showStarted != nil {
317
323
showStarted = nil
318
- animate ( in: false , type: animationType, completion: { ( finished ) in
324
+ animate ( in: false , type: animationType, completion: { _ in
319
325
self . done ( )
320
326
} )
321
327
} else {
@@ -343,7 +349,8 @@ extension HUD {
343
349
bezelView. transform = large
344
350
}
345
351
346
- UIView . animate ( withDuration: 0.3 , delay: 0.0 , usingSpringWithDamping: 1.0 , initialSpringVelocity: 0.0 , options: . beginFromCurrentState, animations: {
352
+ UIView . animate ( withDuration: 0.3 , delay: 0.0 , usingSpringWithDamping: 1.0 ,
353
+ initialSpringVelocity: 0.0 , options: . beginFromCurrentState, animations: {
347
354
if animating {
348
355
self . bezelView. transform = CGAffineTransform . identity
349
356
} else if !animating && type == . zoomIn {
@@ -378,19 +385,22 @@ extension HUD {
378
385
// MARK: - Timer callbacks
379
386
380
387
extension HUD {
381
- @objc private func handleHideTimer( _ timer: Timer ) {
388
+ @objc
389
+ private func handleHideTimer( _ timer: Timer ) {
382
390
let animated = timer. userInfo as? Bool ?? true
383
391
hide ( animated: animated)
384
392
}
385
393
386
- @objc private func handleGraceTimer( _ timer: Timer ) {
394
+ @objc
395
+ private func handleGraceTimer( _ timer: Timer ) {
387
396
// Show the HUD only if the task is still running
388
397
if !isFinished {
389
398
show ( usingAnimation: useAnimation)
390
399
}
391
400
}
392
401
393
- @objc private func handleMinShowTimer( _ timer: Timer ) {
402
+ @objc
403
+ private func handleMinShowTimer( _ timer: Timer ) {
394
404
hide ( usingAnimation: useAnimation)
395
405
}
396
406
}
@@ -468,6 +478,7 @@ extension HUD {
468
478
bezelView. addSubview ( bottomSpacer)
469
479
}
470
480
481
+ // swiftlint:disable function_body_length
471
482
private func updateIndicators( ) {
472
483
switch mode {
473
484
case . indeterminate:
@@ -527,6 +538,7 @@ extension HUD {
527
538
updateViews ( for: contentColor)
528
539
setNeedsUpdateConstraints ( )
529
540
}
541
+ // swiftlint:enable function_body_length
530
542
531
543
private func updateViews( for color: UIColor ) {
532
544
label. textColor = color
@@ -574,6 +586,7 @@ extension HUD {
574
586
// MARK: - Layout
575
587
576
588
extension HUD {
589
+ // swiftlint:disable function_body_length
577
590
open override func updateConstraints( ) {
578
591
var bezelConstraints : [ NSLayoutConstraint ] = [ ]
579
592
let metrics = [ " margin " : margin]
@@ -594,63 +607,80 @@ extension HUD {
594
607
595
608
// Center bezel in container (self), applying the offset if set
596
609
var centeringConstraints : [ NSLayoutConstraint ] = [ ]
597
- centeringConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . centerX, relatedBy: . equal, toItem: self , attribute: . centerX, multiplier: 1.0 , constant: offset. x) )
598
- centeringConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . centerY, relatedBy: . equal, toItem: self , attribute: . centerY, multiplier: 1.0 , constant: offset. y) )
610
+ centeringConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . centerX, relatedBy: . equal, toItem: self ,
611
+ attribute: . centerX, multiplier: 1.0 , constant: offset. x) )
612
+ centeringConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . centerY, relatedBy: . equal, toItem: self ,
613
+ attribute: . centerY, multiplier: 1.0 , constant: offset. y) )
599
614
apply ( priority: UILayoutPriority ( rawValue: 998.0 ) , to: centeringConstraints)
600
615
addConstraints ( centeringConstraints)
601
616
602
617
// Ensure minimum side margin is kept
603
618
var sideConstraints : [ NSLayoutConstraint ] = [ ]
604
- sideConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " |-(>=margin)-[bezelView]-(>=margin)-| " , options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) , metrics: metrics, views: [ " bezelView " : bezelView] ) )
605
- sideConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " V:|-(>=margin)-[bezelView]-(>=margin)-| " , options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) , metrics: metrics, views: [ " bezelView " : bezelView] ) )
619
+ sideConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " |-(>=margin)-[bezelView]-(>=margin)-| " ,
620
+ options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) ,
621
+ metrics: metrics, views: [ " bezelView " : bezelView] ) )
622
+ sideConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " V:|-(>=margin)-[bezelView]-(>=margin)-| " ,
623
+ options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) ,
624
+ metrics: metrics, views: [ " bezelView " : bezelView] ) )
606
625
apply ( priority: UILayoutPriority ( rawValue: 999.0 ) , to: sideConstraints)
607
626
addConstraints ( sideConstraints)
608
627
609
628
// Minimum bezel size, if set
610
629
if !minSize. equalTo ( . zero) {
611
630
var minSizeConstraints : [ NSLayoutConstraint ] = [ ]
612
- minSizeConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . width, relatedBy: . greaterThanOrEqual, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: minSize. width) )
613
- minSizeConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: minSize. height) )
631
+ minSizeConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . width, relatedBy: . greaterThanOrEqual, toItem: nil ,
632
+ attribute: . notAnAttribute, multiplier: 1.0 , constant: minSize. width) )
633
+ minSizeConstraints. append ( NSLayoutConstraint ( item: bezelView, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil ,
634
+ attribute: . notAnAttribute, multiplier: 1.0 , constant: minSize. height) )
614
635
apply ( priority: UILayoutPriority ( rawValue: 997.0 ) , to: minSizeConstraints)
615
636
bezelConstraints. append ( contentsOf: minSizeConstraints)
616
637
}
617
638
618
639
// Square aspect ratio, if set
619
640
if isSquare {
620
- let square = NSLayoutConstraint ( item: bezelView, attribute: . height, relatedBy: . equal, toItem: bezelView, attribute: . width, multiplier: 1.0 , constant: 0.0 )
641
+ let square = NSLayoutConstraint ( item: bezelView, attribute: . height, relatedBy: . equal, toItem: bezelView,
642
+ attribute: . width, multiplier: 1.0 , constant: 0.0 )
621
643
square. priority = UILayoutPriority ( rawValue: 997.0 )
622
644
bezelConstraints. append ( square)
623
645
}
624
646
625
647
// Top and bottom spacing
626
- topSpacer. addConstraint ( NSLayoutConstraint ( item: topSpacer, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: topBottomMargin) )
627
- bottomSpacer. addConstraint ( NSLayoutConstraint ( item: bottomSpacer, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil , attribute: . notAnAttribute, multiplier: 1.0 , constant: topBottomMargin) )
648
+ topSpacer. addConstraint ( NSLayoutConstraint ( item: topSpacer, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil ,
649
+ attribute: . notAnAttribute, multiplier: 1.0 , constant: topBottomMargin) )
650
+ bottomSpacer. addConstraint ( NSLayoutConstraint ( item: bottomSpacer, attribute: . height, relatedBy: . greaterThanOrEqual, toItem: nil ,
651
+ attribute: . notAnAttribute, multiplier: 1.0 , constant: topBottomMargin) )
628
652
629
653
// Top and bottom spaces should be equal
630
- bezelConstraints. append ( NSLayoutConstraint ( item: topSpacer, attribute: . height, relatedBy: . equal, toItem: bottomSpacer, attribute: . height, multiplier: 1.0 , constant: 0.0 ) )
654
+ bezelConstraints. append ( NSLayoutConstraint ( item: topSpacer, attribute: . height, relatedBy: . equal, toItem: bottomSpacer,
655
+ attribute: . height, multiplier: 1.0 , constant: 0.0 ) )
631
656
632
657
// Layout subviews in bezel
633
658
var paddingConstraints : [ NSLayoutConstraint ] = [ ]
634
659
for (idx, view) in subviews. enumerated ( ) {
635
-
636
660
// Center in bezel
637
- bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . centerX, relatedBy: . equal, toItem: bezelView, attribute: . centerX, multiplier: 1.0 , constant: 0.0 ) )
661
+ bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . centerX, relatedBy: . equal, toItem: bezelView,
662
+ attribute: . centerX, multiplier: 1.0 , constant: 0.0 ) )
638
663
639
664
// Ensure the minimum edge margin is kept
640
- bezelConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " |-(>=margin)-[view]-(>=margin)-| " , options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) , metrics: metrics, views: [ " view " : view] ) )
665
+ bezelConstraints. append ( contentsOf: NSLayoutConstraint . constraints ( withVisualFormat: " |-(>=margin)-[view]-(>=margin)-| " ,
666
+ options: NSLayoutConstraint . FormatOptions ( rawValue: 0 ) ,
667
+ metrics: metrics, views: [ " view " : view] ) )
641
668
642
669
// Element spacing
643
670
if idx == 0 {
644
671
// First, ensure spacing to bezel edge
645
- bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . top, relatedBy: . equal, toItem: bezelView, attribute: . top, multiplier: 1.0 , constant: 0.0 ) )
672
+ bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . top, relatedBy: . equal, toItem: bezelView,
673
+ attribute: . top, multiplier: 1.0 , constant: 0.0 ) )
646
674
} else if idx == subviews. count - 1 {
647
675
// Last, ensure spacing to bezel edge
648
- bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . bottom, relatedBy: . equal, toItem: bezelView, attribute: . bottom, multiplier: 1.0 , constant: 0.0 ) )
676
+ bezelConstraints. append ( NSLayoutConstraint ( item: view, attribute: . bottom, relatedBy: . equal, toItem: bezelView,
677
+ attribute: . bottom, multiplier: 1.0 , constant: 0.0 ) )
649
678
}
650
679
651
680
if idx > 0 {
652
681
// Has previous
653
- let padding = NSLayoutConstraint ( item: view, attribute: . top, relatedBy: . equal, toItem: subviews [ idx - 1 ] , attribute: . bottom, multiplier: 1.0 , constant: 0.0 )
682
+ let padding = NSLayoutConstraint ( item: view, attribute: . top, relatedBy: . equal, toItem: subviews [ idx - 1 ] ,
683
+ attribute: . bottom, multiplier: 1.0 , constant: 0.0 )
654
684
bezelConstraints. append ( padding)
655
685
paddingConstraints. append ( padding)
656
686
}
@@ -663,6 +693,7 @@ extension HUD {
663
693
664
694
super. updateConstraints ( )
665
695
}
696
+ // swiftlint:enable function_body_length
666
697
667
698
open override func layoutSubviews( ) {
668
699
// There is no need to update constraints if they are going to
@@ -717,7 +748,8 @@ extension HUD {
717
748
}
718
749
}
719
750
720
- @objc private func updateProgressFromProgressObject( ) {
751
+ @objc
752
+ private func updateProgressFromProgressObject( ) {
721
753
guard let progressObject = progressObject else { return }
722
754
progress = CGFloat ( progressObject. fractionCompleted)
723
755
}
@@ -735,7 +767,8 @@ extension HUD {
735
767
NotificationCenter . default. removeObserver ( self )
736
768
}
737
769
738
- @objc private func statusBarOrientationDidChange( _ notification: Notification ) {
770
+ @objc
771
+ private func statusBarOrientationDidChange( _ notification: Notification ) {
739
772
guard superview != nil else { return }
740
773
updateForCurrentOrientation ( animated: true )
741
774
}
0 commit comments