Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UIBackdropView - iPhone Development Wiki

UIBackdropView

From iPhone Development Wiki
Revision as of 16:28, 24 March 2015 by SimonSelg (talk | contribs) (Added clarification about the apply methods.)

_UIBackdropView is a private class in UIKit.framework (iOS 7.0+), a subclass of UIView, which is used for the popular blur effects.

It uses a CABackdropLayer with a gaussianBlur CAFilter (kCAFilterGaussianBlur) .[1]

Creating Settings

_UIBackdropView uses a _UIBackdropViewSettings object for its setup. There are many ways to create it:

_UIBackdropViewSettings *settings = (_UIBackdropViewSettings *)[[[_UIBackdropViewSettingsSemiLight alloc] init] autorelease];

_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2070];

_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForPrivateStyle:2070]; //this only calls settingsForStyle internally, so there are no advantages of using it over settingsForStyle 

_UIBackdropViewSettings *settings = [[[_UIBackdropViewSettings alloc] initWithDefaultsValue] autorelease];

_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2030 graphicsQuality:100] ; //can be either 10 or 100, 100 is better. See notes at the bottom

Available settings classes (styles) on iOS 7

Here's a list with known settings classes (subclasses of _UIBackdropViewSettings) available in iOS 7.

Class name Style number(s) Comments/Used by
_UIBackdropViewSettingsCombiner -3
_UIBackdropViewSettingsNone -2
_UIBackdropViewSettingsLight 0, 1000, 1003, 2020, 10090, 10100
_UIBackdropViewSettingsDark 1, 1001, 1100, 2030, 11050, 11060 iOS 7 Notification Center (?), keyboard, Safari NavigationBar
_UIBackdropViewSettingsBlur 2 Common blurring
_UIBackdropViewSettingsColorSample 2000
_UIBackdropViewSettingsUltraLight 2010 Some alert views in Settings app & many white UIs
_UIBackdropViewSettingsLightLow 2029
_UIBackdropViewSettingsDarkWithZoom 2031
_UIBackdropViewSettingsDarkLow 2039
_UIBackdropViewSettingsColored 2040 rgba(0.0196078,0.0196078,0.0196078,1)
10091 rgba(0.160784,1,0.301961,1)
10092 rgba(1,0.0980392,0.0470588,1)
10120 rgba(0.0313725,0.262745,0.560784,1)
_UIBackdropViewSettingsUltraDark 2050, 11070
_UIBackdropViewSettingsAdaptiveLight 2060 iOS 7 Control Center
_UIBackdropViewSettingsSemiLight 2070
_UIBackdropViewSettingsFlatSemiLight 2071
_UIBackdropViewSettingsUltraColored 2080
_UIBackdropViewSettingsPasscodePaddle 3900 iOS 7.1+
_UIBackdropViewSettingsLightKeyboard 3901 iOS 7.1+

Available settings classes (styles) on iOS 8

Here are all available settings classes for iOS 8.1:

Class name Style number(s) Comments/Used by
_UIBackdropViewSettingsCombiner -3
_UIBackdropViewSettingsNone -2
_UIBackdropViewSettingsLight 0, 1000, 1003, 2020, 10090, 10100
_UIBackdropViewSettingsDark 1, 1001, 1100, 2030, 11050, 11060 Keyboard, Safari NavigationBar
_UIBackdropViewSettingsBlur 2 Common blurring
_UIBackdropViewSettingsColorSample 2000
_UIBackdropViewSettingsUltraLight 2010, 10060, 10070, 10080, 10050, 10110 Some alert views in Settings app & many white UIs
_UIBackdropViewSettingsLightLow 2029
_UIBackdropViewSettingsDarkWithZoom 2031
_UIBackdropViewSettingsDarkLow 2039
_UIBackdropViewSettingsColored 2040 Default Value of _UIBackdropViewSettingsColored (see notes below). Uses tint color rgba(0.0196078,0.0196078,0.0196078,1)
10091 Uses tint color rgba(0.160784, 1, 0, 1)
10092 Uses tint color rgba(1,0.098039, 0.047059,1)
10120 Uses tint color rgba(0.031373, 0.262745, 0.560784, 1)
_UIBackdropViewSettingsUltraDark 2050, 11070
_UIBackdropViewSettingsAdaptiveLight 2060 iOS 7 Control Center
_UIBackdropViewSettingsSemiLight 2070
_UIBackdropViewSettingsFlatSemiLight 2071
_UIBackdropViewSettingsUltraColored 2080
_UIBackdropViewSettingsPasscodePaddle 3900 iOS 7.1+
_UIBackdropViewSettingsLightKeyboard 3901 iOS 7.1+

Creating Sample

// Creating blur view using settings object
_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2060];

// initialization of the blur view
_UIBackdropView *blurView = [[_UIBackdropView alloc] initWithFrame:CGRectZero
                                              autosizesToFitSuperview:YES settings:settings];
// another way for initialization
_UIBackdropView *blurView = [[_UIBackdropView alloc] initWithSettings:settings];

// or without settings object implementation
_UIBackdropView *blurView = [[_UIBackdropView alloc] initWithStyle:2060];

[someView addSubview:backView];
[blurView release];

About _UIBackdropViewSettingsColored

You can give it a tint color (in fact, it already has a default tint color, and some styles (10091, 10092, 10120) set their own). Example:

_UIBackdropViewSettings *settings = [[_UIBackdropViewSettingsColored alloc]init];
[settings setTintColor:[UIColor colorWithRed:1 green:0 blue: alpha: 1];
//now us it somewhere

Blurring Sample

There are only two blur qualities available.

  • low
  • default (Assumed to be "medium")

They correspend to the kCAFilterGaussianBlur's property "inputQuality"

[blurView setBlurRadiusSetOnce:NO];
[blurView setBlurRadius:10.0];
[blurView setBlurHardEdges:3];
[blurView setBlurWithHardEdges:YES];
[blurView setBlurQuality:@"low"];

Tinting Sample

[blurView setRequiresColorStatistics:YES];
[blurView setUsesColorTintView:YES];
UIColor *color = [UIColor cyanColor];
[blurView setColorTint:color]; // or you may use - (void)transitionToColor:(UIColor *)color;
[blurView setColorTintAlpha:0.8];
[blurView setColorTintMaskAlpha:0.7];

About graphics quality

The styles have different graphic qualities. If you don't specify it, the "best matching" quality for your device is used (using [UIDevice _graphicsQuality]). There are two values: 10 and 100. 100 looks better, but needs more resources. On default, iPad2,6, iPad2,7, iPad3,4, iPad3,5, iPad3,6, iPhone4,1, iPhone5,1, iPhone5,2, iPod5,1 get 100, the other devices get 10 (as of iOS 8.1). To manually set a graphic quality to a style, use

[_UIBackdropViewSettings  settingsForStyle:2030 arg1 graphicsQuality:100]; //replace 2030 and 100 with whatever you need.

If you specify the graphics quality as 10 (or use the default, and it is 10 on the device), the blur quality "low" will be used (if you don't override it).

Applying blur settings/style

There are several ways for doing this by methods.

Signature - (void)transitionIncrementallyToPrivateStyle:(int)style weighting:(float)weight;
Available in 7.0 –
Signature - (void)transitionIncrementallyToStyle:(int)style weighting:(float)weight;
Available in 7.0 –
Signature - (void)transitionToSettings:(_UIBackdropViewSettings *)settings;
Available in 7.0 –
Signature - (void)transitionToPrivateStyle:(int)style;
Available in 7.0 –
Signature - (void)transitionToStyle:(int)style;
Available in 7.0 –

transitionIncrementallyToPrivateStyle and transitionIncrementallyToStyle do the same (transitionIncrementallyToPrivateStyle calls transitionIncrementallyToStyle internally). transitionToSettings and transitionToPrivateStyle are equivalent too.

For example

_UIBackdropViewSettings *newSettings = [_UIBackdropViewSettings settingsForPrivateStyle:0];

// Whatever configuration for the settings

[blurView setInputSettings:newSettings];

Getting/Parsing all _UIBackdropView objects at runtime

NSArray *blurViews = [_UIBackdropView allBackdropViews];

for (_UIBackdropView *view in blurViews) {
      NSLog(@"This _UIBackdropView style is: %d", view.style);
     // do any _UIBackdropView configuration here
}

References