如何检测iPhone我的应用程序是否打开,是否会使用简单的透明效果而不是模糊效果?

Ayu*_*oel 7 iphone objective-c ios ios7

我在运行iOS 7的iPhone 4上的应用程序使用带有自定义的UITabBar barTintColor.如Apple文档中所述:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UITabBar.html

默认情况下,iOS 7上的标签栏是半透明的.此外,系统模糊应用于所有标签栏.这允许您的内容通过栏下方显示.

但是这种系统模糊在iPhone 4上不可见,并且UITabBar在设备上变得透明,如下所示:

相信这可能会发生,因为iPhone 4中的GPU较弱,因此它必须回归透明而不是半透明.参考:http://arstechnica.com/apple/2013/09/new-lease-on-life-or-death-sentence-ios-7-on-the-iphone-4/

一个简单的解决方案就是UITabBar translucent有条不紊地制作适用于iPhone 4.但是我不想把这种依赖性放在设备类型上,我想知道我是否能以某种方式检测当GPU弱的时候iOS是否会回落到透明度?(从而使条件更合适)

dat*_*inc 6

以下是一些快速且脏的类别,可检测设备是否支持模糊.希望它能解决你的问题

@interface UIToolbar (support)
@property (nonatomic, readonly) BOOL supportsBlur;
@end

@implementation UIToolbar (support)
    -(BOOL) supportsBlur{
        return [self _supportsBlur:self];
    }


    -(BOOL)_supportsBlur:(UIView*) view{
        if ([view isKindOfClass:NSClassFromString(@"_UIBackdropEffectView")]){
            return YES;
        }

        for (UIView* subview in view.subviews){
            if ([self _supportsBlur:subview]){
                return YES;
            }
        }
        return NO;
    }
@end

// Use this category to detect if the device supports blur
@interface UIDevice (support)
@property (nonatomic, readonly) BOOL supportsBlur;
@end


@implementation UIDevice (support)
    -(BOOL) supportsBlur{
        static BOOL supportsBlur = NO;
        static dispatch_once_t onceToken = 0;
        dispatch_once(&onceToken, ^{
            UIToolbar* toolBar = [[UIToolbar alloc] init];
            [toolBar layoutSubviews];
            supportsBlur = toolBar.supportsBlur;
        });
        return supportsBlur;
    }
@end
Run Code Online (Sandbox Code Playgroud)