如何检测iOS设备是否支持模糊效果? [英] How can I detect if an iOS device supports the blur effect?
问题描述
看来不同的iOS设备使用 barStyle = UIBarStyleBlack
和半透明渲染
非常不同。考虑: UINavigationBar
= YES
It appears that different iOS devices render UINavigationBar
s with barStyle = UIBarStyleBlack
and translucent = YES
very differently. Consider:
iPhone 4,没有色调:
iPhone 4, no tint:
iPhone 5,没有色调:
iPhone 5, no tint:
iPhone 4, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f ]
:
iPhone 4, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f]
:
iPhone 5, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f]
:
iPhone 5, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f]
:
iPhone 5产生没有色调的效果,但是4是不透明的。添加一个半透明的色调使4看起来很好,但拧紧5。
The iPhone 5 produces the desired effect without a tint, but the 4 is opaque. Adding a semitransparent tint makes the 4 look good, but screws up the 5.
iPad 2和3也是如此,理论上任何不支持的设备都是如此iOS 7模糊效果。
The same holds true for the iPad 2 and 3, and theoretically any device that does not support the iOS 7 blur effects.
如果没有将这些旧设备列入黑名单,我如何检测设备是否支持模糊,以便我可以有条件地解决渲染差异?或者有没有办法在不使用色调的情况下规范化外观?
Short of blacklisting these older devices, how can I detect if a device supports the blurring so that I can conditionally work around the rendering differences? Or is there a way to normalize the appearance without using a tint at all?
推荐答案
这个UIDevice类别如何以及观察UIAccessibilityReduceTransparencyStatusDidChangeNotification?
What about this UIDevice category along with observing for UIAccessibilityReduceTransparencyStatusDidChangeNotification?
@interface UIDevice (Additions)
@property (readonly) NSString *platform;
@property (readonly) BOOL canBlur;
@end
@implementation UIDevice (Additions)
- (NSString *)platform {
int mib[] = { CTL_HW, HW_MACHINE };
size_t len = 0;
sysctl(mib, 2, NULL, &len, NULL, 0);
char *machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
return platform;
}
- (BOOL)canBlur {
if(NSStringFromClass([UIVisualEffectView class]) && UIDevice.currentDevice.systemVersion.floatValue >= 8.0 && !UIAccessibilityIsReduceTransparencyEnabled()) {
NSString *platform = self.platform;
CGFloat deviceVersion = [[[platform stringByReplacingOccurrencesOfString:@"[^0-9,.]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, platform.length)] stringByReplacingOccurrencesOfString:@"," withString:@"."] floatValue];
if([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]) {
return YES;
} else if([platform rangeOfString:@"iPhone"].location != NSNotFound) {
return (deviceVersion >= 4.1);
} else if([platform rangeOfString:@"iPod"].location != NSNotFound) {
return (deviceVersion >= 5.1);
} else if([platform rangeOfString:@"iPad"].location != NSNotFound) {
return (deviceVersion >= 3.4);
}
}
return NO;
}
不要忘记在实施文件中使用#include。
Don't forget to #include in your implementation file.
这篇关于如何检测iOS设备是否支持模糊效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!