Sergey Grishchev
Sergey Grishchev

Reputation: 12051

Standard iOS 7 blur implementation

I have read dozens of questions about mimicking iOS 7 blur effect in earlier versions of iOS. But the fundamental question that arises here is does iOS 7's UIKit really have a nice and convenient way to make any UIView blurred? That seems quite logical to me. Any help appreciated.

Upvotes: 25

Views: 13412

Answers (3)

rob mayoff
rob mayoff

Reputation: 385680

UPDATE

As of iOS 8.0 (not iOS 7), UIKit provides UIVisualEffectView and UIBlurEffect. You can watch WWDC 2014 Session 419 “Advanced Graphics and Animations for iOS Apps” (or just download the slides) for an introduction to these classes.

ORIGINAL

No, it doesn't. Apple has not exposed an interface for doing this conveniently. For example, if you read through this discussion, Rincewind's responses should make it clear that Apple doesn't provide a public API for this, and that the private APIs they use have serious limits and are likely to change.

You must implement the blur effect yourself. You'll probably want to use the new -[UIView drawViewHierarchyInRect:afterScreenUpdates:] method to capture the appearance of the background view, and then apply a CIFilter to it to perform the blur.

Upvotes: 26

Marco
Marco

Reputation: 15027

Apple has provided sample code to blur any UIImage in iOS 7's style.

Go to Apple Developer downloads and log in if necessary. Search for "imageeffects" to bring up the WWDC 2013 Sample Code entry, and download the iOS_UIImageEffects sample code.

In that project, there's a UIImage category in UIImage+ImageEffects.h that you can copy into your own project, containing the applyBlurWithRadius:... method.

You'll need to link your project with the Accelerate framework.

This won't automatically do a blur on a view in realtime — for that, see FXBlurView, which performs a similar technique by automatically snapshotting its superview. It can be pretty performance-intensive, though: consider first whether you can achieve what you want by statically blurring an image, rather than trying to "live"-blur moving content.

Upvotes: 27

ArtSabintsev
ArtSabintsev

Reputation: 5190

UIKit does not have a convenient way of achieving this effect. However, there's a few libraries on Github that easily achieve this effect. Nick Lockwood's seems to be the most popular.

Upvotes: 4

Related Questions