Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 077e5e0

Browse files
author
Tobias Tiemerding
committed
1 parent ba369a1 commit 077e5e0

5 files changed

Lines changed: 64 additions & 82 deletions

File tree

Demo/Classes/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ - (void)viewWillAppear:(BOOL)animated {
3838
}
3939

4040
- (void)handleNotification:(NSNotification *)notification {
41-
NSLog(@"Notification recieved: %@", notification.name);
41+
NSLog(@"Notification received: %@", notification.name);
4242
NSLog(@"Status user info key: %@", notification.userInfo[SVProgressHUDStatusUserInfoKey]);
4343
}
4444

Demo/SVProgressHUD.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
080E96DDFE201D6D7F000001 /* iOS Demo */ = {
9898
isa = PBXGroup;
9999
children = (
100+
63ADC4B81364C1360060E45B /* SVProgressHUD */,
100101
28D7ACF60DDB3853001CB0EB /* ViewController.h */,
101102
28D7ACF70DDB3853001CB0EB /* ViewController.m */,
102103
2899E5210DE3E06400AC0155 /* ViewController.xib */,
@@ -139,7 +140,6 @@
139140
8D1107310486CEB800E47090 /* SVProgressHUD-Info.plist */,
140141
32CA4F630368D1EE00C91783 /* SVProgressHUD_Prefix.pch */,
141142
29B97316FDCFA39411CA2CEA /* main.m */,
142-
63ADC4B81364C1360060E45B /* SVProgressHUD */,
143143
);
144144
name = "Other Sources";
145145
path = ..;
@@ -170,7 +170,7 @@
170170
3CD078E91A3B809500290D80 /* SVRadialGradientLayer.m */,
171171
);
172172
name = SVProgressHUD;
173-
path = ../SVProgressHUD;
173+
path = ../../SVProgressHUD;
174174
sourceTree = "<group>";
175175
};
176176
D36EDBCF1BE7E9B000BD0EF1 /* tvOS Demo */ = {

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ pod install
3939

4040
### Carthage
4141

42-
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
43-
44-
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
45-
46-
```bash
47-
$ brew update
48-
$ brew install carthage
49-
```
50-
51-
To integrate `SVProgressHUD` into your Xcode project using Carthage, specify it in your `Cartfile`:
42+
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate `SVProgressHUD` into your Xcode project using Carthage, specify it in your `Cartfile`:
5243

5344
```ogdl
5445
github "SVProgressHUD/SVProgressHUD"

SVProgressHUD/SVProgressHUD.m

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
344344
_defaultMaskType = SVProgressHUDMaskTypeNone;
345345
_defaultStyle = SVProgressHUDStyleLight;
346346
_defaultAnimationType = SVProgressHUDAnimationTypeFlat;
347+
_minimumSize = CGSizeMake(100.0f, 100.0f);
347348

348349
if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) {
349350
_font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
@@ -395,12 +396,14 @@ - (instancetype)initWithFrame:(CGRect)frame {
395396
- (void)updateHUDFrame {
396397
// For the beginning use default values, these
397398
// might get update if string is too large etc.
398-
CGFloat hudWidth = 100.0f;
399-
CGFloat hudHeight = 100.0f;
400-
CGFloat stringHeightBuffer = 20.0f;
401-
CGFloat stringAndContentHeightBuffer = 80.0f;
399+
CGFloat hudWidth;
400+
CGFloat hudHeight;
402401
CGRect labelRect = CGRectZero;
403402

403+
CGFloat verticalSpacing = 12.0f; // |-12-content-(8-label-)12-|
404+
CGFloat horizontalSpacing = 12.0f; // |-12-content-12-|
405+
CGFloat progressLabelSpacing = 8.0f; // content-8-label; progess = spinner or image
406+
404407
// Check if an image or progress ring is displayed
405408
BOOL imageUsed = (self.imageView.image) && !(self.imageView.hidden);
406409
BOOL progressUsed = self.imageView.hidden;
@@ -409,12 +412,11 @@ - (void)updateHUDFrame {
409412
NSString *string = self.statusLabel.text;
410413
if(string) {
411414
CGSize constraintSize = CGSizeMake(200.0f, 300.0f);
412-
CGRect stringRect;
413415
if([string respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
414-
stringRect = [string boundingRectWithSize:constraintSize
415-
options:(NSStringDrawingOptions)(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin)
416-
attributes:@{NSFontAttributeName: self.statusLabel.font}
417-
context:NULL];
416+
labelRect = [string boundingRectWithSize:constraintSize
417+
options:(NSStringDrawingOptions)(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin)
418+
attributes:@{NSFontAttributeName: self.statusLabel.font}
419+
context:NULL];
418420
} else {
419421
CGSize stringSize;
420422
if([string respondsToSelector:@selector(sizeWithAttributes:)]) {
@@ -427,75 +429,55 @@ - (void)updateHUDFrame {
427429
#pragma clang diagnostic pop
428430
#endif
429431
}
430-
stringRect = CGRectMake(0.0f, 0.0f, stringSize.width, stringSize.height);
432+
labelRect = CGRectMake(0.0f, 0.0f, stringSize.width, stringSize.height);
431433
}
432-
433-
CGFloat stringWidth = stringRect.size.width;
434-
CGFloat stringHeight = ceilf(CGRectGetHeight(stringRect));
434+
labelRect.size.width = MAX(self.minimumSize.width, horizontalSpacing + CGRectGetWidth(labelRect) + horizontalSpacing);
435+
436+
CGFloat labelHeight = ceilf(CGRectGetHeight(labelRect));
437+
CGFloat labelWidth = ceilf(CGRectGetWidth(labelRect));
435438

436439
if(imageUsed || progressUsed) {
437-
hudHeight = stringAndContentHeightBuffer + stringHeight;
440+
CGFloat contentHeight = (imageUsed ? CGRectGetHeight(self.imageView.frame) : CGRectGetHeight(self.indefiniteAnimatedView.frame));
441+
hudHeight = verticalSpacing + contentHeight + progressLabelSpacing + labelHeight + verticalSpacing;
438442
} else {
439-
hudHeight = stringHeightBuffer + stringHeight;
440-
}
441-
if(stringWidth > hudWidth) {
442-
hudWidth = ceilf(stringWidth/2)*2;
443-
}
444-
CGFloat labelRectY = (imageUsed || progressUsed) ? 68.0f : 9.0f;
445-
if(hudHeight > 100.0f) {
446-
labelRect = CGRectMake(12.0f, labelRectY, hudWidth, stringHeight);
447-
hudWidth += 24.0f;
448-
} else {
449-
hudWidth += 24.0f;
450-
labelRect = CGRectMake(0.0f, labelRectY, hudWidth, stringHeight);
443+
hudHeight = verticalSpacing + labelHeight + verticalSpacing;
451444
}
445+
hudWidth = labelWidth;
452446
}
453447

454448
// Update values on subviews
455449
self.hudView.bounds = CGRectMake(0.0f, 0.0f, MAX(self.minimumSize.width, hudWidth), MAX(self.minimumSize.height, hudHeight));
456-
labelRect.size.width += MAX(0, self.minimumSize.width - hudWidth);
457450
[self updateBlurBounds];
458451

459-
if(string) {
460-
self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, 36.0f);
461-
} else {
462-
self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, CGRectGetHeight(self.hudView.bounds)/2);
463-
}
464-
465-
self.statusLabel.hidden = NO;
466-
self.statusLabel.frame = labelRect;
467-
468452
// Animate value update
469453
[CATransaction begin];
470454
[CATransaction setDisableActions:YES];
471455

472-
if(string) {
473-
if(self.defaultAnimationType == SVProgressHUDAnimationTypeFlat) {
474-
SVIndefiniteAnimatedView *indefiniteAnimationView = (SVIndefiniteAnimatedView*)self.indefiniteAnimatedView;
475-
indefiniteAnimationView.radius = self.ringRadius;
476-
[indefiniteAnimationView sizeToFit];
477-
}
478-
479-
CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36.0f);
480-
self.indefiniteAnimatedView.center = center;
456+
// Spinner and image view
457+
CGFloat centerY;
458+
if(string){
459+
CGFloat contentHeight = (imageUsed ? CGRectGetHeight(self.imageView.frame) : CGRectGetHeight(self.indefiniteAnimatedView.frame));
460+
CGFloat labelHeight = ceilf(CGRectGetHeight(labelRect));
461+
CGFloat yOffset = MAX(verticalSpacing, (self.minimumSize.height - contentHeight - progressLabelSpacing - labelHeight) / 2.0f);
481462

482-
if(self.progress != SVProgressHUDUndefinedProgress) {
483-
self.backgroundRingView.center = self.ringView.center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36.0f);
484-
}
485-
} else {
486-
if(self.defaultAnimationType == SVProgressHUDAnimationTypeFlat) {
487-
SVIndefiniteAnimatedView *indefiniteAnimationView = (SVIndefiniteAnimatedView*)self.indefiniteAnimatedView;
488-
indefiniteAnimationView.radius = self.ringNoTextRadius;
489-
[indefiniteAnimationView sizeToFit];
490-
}
491-
492-
CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2);
493-
self.indefiniteAnimatedView.center = center;
494-
495-
if(self.progress != SVProgressHUDUndefinedProgress) {
496-
self.backgroundRingView.center = self.ringView.center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2);
497-
}
463+
centerY = yOffset + contentHeight / 2.0f;
464+
} else {
465+
centerY = CGRectGetHeight(self.hudView.bounds) / 2.0f;
466+
}
467+
self.indefiniteAnimatedView.center = CGPointMake((CGRectGetWidth(self.hudView.bounds) / 2.0f), centerY);
468+
if(self.progress != SVProgressHUDUndefinedProgress) {
469+
self.backgroundRingView.center = self.ringView.center = CGPointMake((CGRectGetWidth(self.hudView.bounds) / 2.0f), centerY);
498470
}
471+
self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds) / 2.0f, centerY);
472+
473+
// Label
474+
if(imageUsed || progressUsed){
475+
labelRect.origin.y = (imageUsed ? CGRectGetMaxY(self.imageView.frame) : CGRectGetMaxY(self.indefiniteAnimatedView.frame)) + progressLabelSpacing;
476+
} else {
477+
labelRect.origin.y = verticalSpacing;
478+
}
479+
self.statusLabel.frame = labelRect;
480+
self.statusLabel.hidden = !string;
499481

500482
[CATransaction commit];
501483
}
@@ -693,15 +675,17 @@ - (void)positionHUD:(NSNotification*)notification {
693675
#if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS
694676
self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;
695677
UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
696-
#elif !defined(SV_APP_EXTENSIONS)
697-
self.frame = [UIApplication sharedApplication].keyWindow.bounds;
678+
#elif !defined(SV_APP_EXTENSIONS) && !TARGET_OS_IOS
679+
self.frame= [UIApplication sharedApplication].keyWindow.bounds;
698680
#else
699681
if (self.viewForExtension) {
700682
self.frame = self.viewForExtension.frame;
701683
} else {
702684
self.frame = UIScreen.mainScreen.bounds;
703685
}
686+
#if TARGET_OS_IOS
704687
UIInterfaceOrientation orientation = CGRectGetWidth(self.frame) > CGRectGetHeight(self.frame) ? UIInterfaceOrientationLandscapeLeft : UIInterfaceOrientationPortrait;
688+
#endif
705689
#endif
706690

707691
// no transforms applied to window in iOS 8, but only if compiled with iOS 8 sdk as base sdk, otherwise system supports old rotation logic.
@@ -799,7 +783,7 @@ - (void)positionHUD:(NSNotification*)notification {
799783
__weak SVProgressHUD *weakSelf = self;
800784
[UIView animateWithDuration:animationDuration
801785
delay:0
802-
options:UIViewAnimationOptionAllowUserInteraction
786+
options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState)
803787
animations:^{
804788
__strong SVProgressHUD *strongSelf = weakSelf;
805789
if(strongSelf) {
@@ -867,10 +851,17 @@ - (void)showProgress:(float)progress status:(NSString*)status {
867851
// Cancel the indefiniteAnimatedView, then show the ringLayer
868852
[strongSelf cancelIndefiniteAnimatedViewAnimation];
869853

870-
// Add ring to HUD and set progress
871-
[strongSelf.hudView addSubview:strongSelf.ringView];
872-
[strongSelf.hudView addSubview:strongSelf.backgroundRingView];
854+
// Add ring to HUD
855+
if(!strongSelf.ringView.superview)
856+
[strongSelf.hudView addSubview:strongSelf.ringView];
857+
if(!strongSelf.backgroundRingView.superview)
858+
[strongSelf.hudView addSubview:strongSelf.backgroundRingView];
859+
860+
// Set progress animated
861+
[CATransaction begin];
862+
[CATransaction setDisableActions:YES];
873863
strongSelf.ringView.strokeEnd = progress;
864+
[CATransaction commit];
874865

875866
// Update the activity count
876867
if(progress == 0) {
@@ -988,7 +979,7 @@ __block void (^completionBlock)(void) = ^{
988979
if(strongSelf) {
989980
// Check if we really achieved to show the HUD (<=> alpha values are applied)
990981
// and the change of these values has not been cancelled in between
991-
// e.g. due to a dismissmal
982+
// e.g. due to a dismissal
992983
if(strongSelf.alpha == 1.0f && strongSelf.hudView.alpha == 1.0f){
993984
// Register observer <=> we now have to handle orientation changes etc.
994985
[strongSelf registerNotifications];

SVProgressHUD/SVRadialGradientLayer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ @implementation SVRadialGradientLayer
1212
- (void)drawInContext:(CGContextRef)context {
1313
size_t locationsCount = 2;
1414
CGFloat locations[2] = {0.0f, 1.0f};
15-
CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
15+
CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f};
1616
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
1717
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
1818
CGColorSpaceRelease(colorSpace);

0 commit comments

Comments
 (0)