[英]How can I detect if the iPhone my app is on, is going to use a simple transparent effect instead of the blur effect?
[英]How can I detect if an iOS device supports the blur effect?
看来不同的iOS设备使用barStyle = UIBarStyleBlack
和translucent = YES
渲染UINavigationBar
的方式非常不同。 考虑:
iPhone 4,没有色调:
iPhone 5,没有色调:
iPhone 4, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f]
:
iPhone 5, barTintColor = [UIColor colorWithWhite:0.0f alpha:0.5f]
:
iPhone 5在没有色调的情况下产生所需的效果,但4是不透明的。 添加半透明色调使4看起来很好,但拧紧5。
iPad 2和3也是如此,理论上任何不支持iOS 7模糊效果的设备也是如此。
如果没有将这些旧设备列入黑名单,我如何检测设备是否支持模糊,以便我可以有条件地解决渲染差异? 或者有没有办法在不使用色调的情况下标准化外观?
这个UIDevice类别以及观察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。
我认为这个问题就是你想要做的。 只是为不同的设备编写条件代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.