Skip to content

Commit ca93b61

Browse files
committed
Fixed runtime checks for UIBlurEffect.
1 parent f663584 commit ca93b61

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

MBProgressHUD.m

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,8 @@ @interface MBBackgroundView ()
10271027

10281028
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
10291029
@property UIVisualEffectView *effectView;
1030-
# else
1031-
@property UIToolbar *toolbar;
10321030
#endif
1031+
@property UIToolbar *toolbar;
10331032

10341033
@end
10351034

@@ -1042,11 +1041,11 @@ - (instancetype)initWithFrame:(CGRect)frame {
10421041
if ((self = [super initWithFrame:frame])) {
10431042
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
10441043
_style = MBProgressHUDBackgroundStyleBlur;
1045-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1046-
_color = [UIColor colorWithWhite:0.8f alpha:0.6f];
1047-
#else
1048-
_color = [UIColor colorWithWhite:0.95f alpha:0.6f];
1049-
#endif
1044+
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) {
1045+
_color = [UIColor colorWithWhite:0.8f alpha:0.6f];
1046+
} else {
1047+
_color = [UIColor colorWithWhite:0.95f alpha:0.6f];
1048+
}
10501049
} else {
10511050
_style = MBProgressHUDBackgroundStyleSolidColor;
10521051
_color = [[UIColor blackColor] colorWithAlphaComponent:0.8];
@@ -1093,42 +1092,49 @@ - (void)updateForBackgroundStyle {
10931092
MBProgressHUDBackgroundStyle style = self.style;
10941093
if (style == MBProgressHUDBackgroundStyleBlur) {
10951094
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1096-
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
1097-
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
1098-
[self addSubview:effectView];
1099-
effectView.frame = self.bounds;
1100-
effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
1101-
self.backgroundColor = self.color;
1102-
self.layer.allowsGroupOpacity = NO;
1103-
self.effectView = effectView;
1104-
#else
1105-
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectInset(self.bounds, -100.f, -100.f)];
1106-
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
1107-
toolbar.barTintColor = self.color;
1108-
toolbar.translucent = YES;
1109-
toolbar.barTintColor = color;
1110-
[self addSubview:toolbar];
1111-
self.toolbar = toolbar;
1095+
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) {
1096+
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
1097+
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
1098+
[self addSubview:effectView];
1099+
effectView.frame = self.bounds;
1100+
effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
1101+
self.backgroundColor = self.color;
1102+
self.layer.allowsGroupOpacity = NO;
1103+
self.effectView = effectView;
1104+
} else {
1105+
#endif
1106+
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectInset(self.bounds, -100.f, -100.f)];
1107+
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
1108+
toolbar.barTintColor = self.color;
1109+
toolbar.translucent = YES;
1110+
[self addSubview:toolbar];
1111+
self.toolbar = toolbar;
1112+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1113+
}
11121114
#endif
11131115
} else {
11141116
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1115-
[self.effectView removeFromSuperview];
1116-
self.effectView = nil;
1117-
#else
1118-
[self.toolbar removeFromSuperview];
1119-
self.toolbar = nil;
1117+
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) {
1118+
[self.effectView removeFromSuperview];
1119+
self.effectView = nil;
1120+
} else {
1121+
#endif
1122+
[self.toolbar removeFromSuperview];
1123+
self.toolbar = nil;
1124+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1125+
}
11201126
#endif
11211127
self.backgroundColor = self.color;
11221128
}
11231129
}
11241130

11251131
- (void)updateViewsForColor:(UIColor *)color {
11261132
if (self.style == MBProgressHUDBackgroundStyleBlur) {
1127-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 || TARGET_OS_TV
1128-
self.backgroundColor = self.color;
1129-
#else
1130-
self.toolbar.barTintColor = color;
1131-
#endif
1133+
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0) {
1134+
self.backgroundColor = self.color;
1135+
} else {
1136+
self.toolbar.barTintColor = color;
1137+
}
11321138
} else {
11331139
self.backgroundColor = self.color;
11341140
}

0 commit comments

Comments
 (0)