Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if the iPhone my app is on, is going to use a simple transparent effect instead of the blur effect?

My app on iPhone 4 running iOS 7 uses a UITabBar with a custom barTintColor. As mentioned in Apple documentation : https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UITabBar.html

Tab bars are translucent by default on iOS 7. Additionally, there is a system blur applied to all tab bars. This allows your content to show through underneath the bar.

But this system blur is not visible on iPhone 4 and the UITabBar goes transparent on the device as shown below:

I believe that this might be happening because of the weaker GPU in iPhone 4 and thus it must be falling back to transparency instead of translucency. Reference : http://arstechnica.com/apple/2013/09/new-lease-on-life-or-death-sentence-ios-7-on-the-iphone-4/

A simple solution to this can be to conditionally make the UITabBar translucent for iPhone 4. But instead of putting this dependancy on the device type, I want to know if I can somehow detect if the iOS is going to be falling back to transparency when GPU is weak? (Thus making the condition more appropriate)

like image 515
Ayush Goel Avatar asked Feb 06 '14 12:02

Ayush Goel


1 Answers

Here are some quick and dirty categories that detects if the device supports blur. Hope it solves your problem

@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
like image 181
datinc Avatar answered Sep 27 '22 16:09

datinc