From 257ec88cbc207fc7a55baefc1b1c129d354d8bd7 Mon Sep 17 00:00:00 2001 From: Matej Bukovinski Date: Sun, 4 Nov 2018 18:53:31 +0100 Subject: [PATCH] Remove legacy checks (deployment target is already >= iOS 8) --- MBProgressHUD.m | 144 ++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 114 deletions(-) diff --git a/MBProgressHUD.m b/MBProgressHUD.m index a11cb5e44..b96d99a0e 100644 --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -7,15 +7,6 @@ #import "MBProgressHUD.h" #import - -#ifndef kCFCoreFoundationVersionNumber_iOS_7_0 - #define kCFCoreFoundationVersionNumber_iOS_7_0 847.20 -#endif - -#ifndef kCFCoreFoundationVersionNumber_iOS_8_0 - #define kCFCoreFoundationVersionNumber_iOS_8_0 1129.15 -#endif - #define MBMainThreadAssert() NSAssert([NSThread isMainThread], @"MBProgressHUD needs to be accessed on the main thread."); CGFloat const MBProgressMaxOffset = 1000000.f; @@ -90,10 +81,8 @@ - (void)commonInit { _mode = MBProgressHUDModeIndeterminate; _margin = 20.0f; _defaultMotionEffectsEnabled = YES; + _contentColor = [UIColor colorWithWhite:0.f alpha:0.7f]; - // Default color, depending on the current iOS version - BOOL isLegacy = kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_7_0; - _contentColor = isLegacy ? [UIColor whiteColor] : [UIColor colorWithWhite:0.f alpha:0.7f]; // Transparent background self.opaque = NO; self.backgroundColor = [UIColor clearColor]; @@ -275,15 +264,7 @@ - (void)animateIn:(BOOL)animatingIn withType:(MBProgressHUDAnimation)type comple bezelView.alpha = alpha; self.backgroundView.alpha = alpha; }; - - // Spring animations are nicer, but only available on iOS 7+ -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 || TARGET_OS_TV - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) { - [UIView animateWithDuration:0.3 delay:0. usingSpringWithDamping:1.f initialSpringVelocity:0.f options:UIViewAnimationOptionBeginFromCurrentState animations:animations completion:completion]; - return; - } -#endif - [UIView animateWithDuration:0.3 delay:0. options:UIViewAnimationOptionBeginFromCurrentState animations:animations completion:completion]; + [UIView animateWithDuration:0.3 delay:0. usingSpringWithDamping:1.f initialSpringVelocity:0.f options:UIViewAnimationOptionBeginFromCurrentState animations:animations completion:completion]; } - (void)done { @@ -870,11 +851,10 @@ - (void)setBackgroundTintColor:(UIColor *)backgroundTintColor { - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); - BOOL isPreiOS7 = kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_7_0; if (_annular) { // Draw background - CGFloat lineWidth = isPreiOS7 ? 5.f : 2.f; + CGFloat lineWidth = 2.f; UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath]; processBackgroundPath.lineWidth = lineWidth; processBackgroundPath.lineCapStyle = kCGLineCapButt; @@ -887,7 +867,7 @@ - (void)drawRect:(CGRect)rect { [processBackgroundPath stroke]; // Draw progress UIBezierPath *processPath = [UIBezierPath bezierPath]; - processPath.lineCapStyle = isPreiOS7 ? kCGLineCapRound : kCGLineCapSquare; + processPath.lineCapStyle = kCGLineCapSquare; processPath.lineWidth = lineWidth; endAngle = (self.progress * 2 * (float)M_PI) + startAngle; [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; @@ -902,33 +882,20 @@ - (void)drawRect:(CGRect)rect { [_progressTintColor setStroke]; [_backgroundTintColor setFill]; CGContextSetLineWidth(context, lineWidth); - if (isPreiOS7) { - CGContextFillEllipseInRect(context, circleRect); - } CGContextStrokeEllipseInRect(context, circleRect); // 90 degrees CGFloat startAngle = - ((float)M_PI / 2.f); // Draw progress - if (isPreiOS7) { - CGFloat radius = (CGRectGetWidth(self.bounds) / 2.f) - lineWidth; - CGFloat endAngle = (self.progress * 2.f * (float)M_PI) + startAngle; - [_progressTintColor setFill]; - CGContextMoveToPoint(context, center.x, center.y); - CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); - CGContextClosePath(context); - CGContextFillPath(context); - } else { - UIBezierPath *processPath = [UIBezierPath bezierPath]; - processPath.lineCapStyle = kCGLineCapButt; - processPath.lineWidth = lineWidth * 2.f; - CGFloat radius = (CGRectGetWidth(self.bounds) / 2.f) - (processPath.lineWidth / 2.f); - CGFloat endAngle = (self.progress * 2.f * (float)M_PI) + startAngle; - [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; - // Ensure that we don't get color overlapping when _progressTintColor alpha < 1.f. - CGContextSetBlendMode(context, kCGBlendModeCopy); - [_progressTintColor set]; - [processPath stroke]; - } + UIBezierPath *processPath = [UIBezierPath bezierPath]; + processPath.lineCapStyle = kCGLineCapButt; + processPath.lineWidth = lineWidth * 2.f; + CGFloat radius = (CGRectGetWidth(self.bounds) / 2.f) - (processPath.lineWidth / 2.f); + CGFloat endAngle = (self.progress * 2.f * (float)M_PI) + startAngle; + [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; + // Ensure that we don't get color overlapping when _progressTintColor alpha < 1.f. + CGContextSetBlendMode(context, kCGBlendModeCopy); + [_progressTintColor set]; + [processPath stroke]; } } @@ -959,8 +926,7 @@ - (id)initWithFrame:(CGRect)frame { #pragma mark - Layout - (CGSize)intrinsicContentSize { - BOOL isPreiOS7 = kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_7_0; - return CGSizeMake(120.f, isPreiOS7 ? 20.f : 10.f); + return CGSizeMake(120.f, 10.f); } #pragma mark - Properties @@ -1067,12 +1033,7 @@ - (void)drawRect:(CGRect)rect { @interface MBBackgroundView () -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV @property UIVisualEffectView *effectView; -#endif -#if !TARGET_OS_TV -@property UIToolbar *toolbar; -#endif @end @@ -1083,20 +1044,9 @@ @implementation MBBackgroundView - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) { - _style = MBProgressHUDBackgroundStyleBlur; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV - _blurEffectStyle = UIBlurEffectStyleLight; -#endif - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) { - _color = [UIColor colorWithWhite:0.8f alpha:0.6f]; - } else { - _color = [UIColor colorWithWhite:0.95f alpha:0.6f]; - } - } else { - _style = MBProgressHUDBackgroundStyleSolidColor; - _color = [[UIColor blackColor] colorWithAlphaComponent:0.8]; - } + _style = MBProgressHUDBackgroundStyleBlur; + _blurEffectStyle = UIBlurEffectStyleLight; + _color = [UIColor colorWithWhite:0.8f alpha:0.6f]; self.clipsToBounds = YES; @@ -1115,9 +1065,6 @@ - (CGSize)intrinsicContentSize { #pragma mark - Appearance - (void)setStyle:(MBProgressHUDBackgroundStyle)style { - if (style == MBProgressHUDBackgroundStyleBlur && kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_7_0) { - style = MBProgressHUDBackgroundStyleSolidColor; - } if (_style != style) { _style = style; [self updateForBackgroundStyle]; @@ -1150,44 +1097,19 @@ - (void)setBlurEffectStyle:(UIBlurEffectStyle)blurEffectStyle { #pragma mark - Views - (void)updateForBackgroundStyle { -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) { - [self.effectView removeFromSuperview]; - self.effectView = nil; - } else { -#endif -#if !TARGET_OS_TV - [self.toolbar removeFromSuperview]; - self.toolbar = nil; -#endif -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV - } -#endif + [self.effectView removeFromSuperview]; + self.effectView = nil; + MBProgressHUDBackgroundStyle style = self.style; if (style == MBProgressHUDBackgroundStyleBlur) { -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) { - UIBlurEffect *effect = [UIBlurEffect effectWithStyle:self.blurEffectStyle]; - UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect]; - [self insertSubview:effectView atIndex:0]; - effectView.frame = self.bounds; - effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - self.backgroundColor = self.color; - self.layer.allowsGroupOpacity = NO; - self.effectView = effectView; - } else { -#endif -#if !TARGET_OS_TV - UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectInset(self.bounds, -100.f, -100.f)]; - toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - toolbar.barTintColor = self.color; - toolbar.translucent = YES; - [self addSubview:toolbar]; - self.toolbar = toolbar; -#endif -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV - } -#endif + UIBlurEffect *effect = [UIBlurEffect effectWithStyle:self.blurEffectStyle]; + UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect]; + [self insertSubview:effectView atIndex:0]; + effectView.frame = self.bounds; + effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + self.backgroundColor = self.color; + self.layer.allowsGroupOpacity = NO; + self.effectView = effectView; } else { self.backgroundColor = self.color; } @@ -1195,13 +1117,7 @@ - (void)updateForBackgroundStyle { - (void)updateViewsForColor:(UIColor *)color { if (self.style == MBProgressHUDBackgroundStyleBlur) { - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) { - self.backgroundColor = self.color; - } else { -#if !TARGET_OS_TV - self.toolbar.barTintColor = color; -#endif - } + self.backgroundColor = self.color; } else { self.backgroundColor = self.color; }