Standard iOS 7 blur implementation

13,395

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
13,395

Related videos on Youtube

Sergey Grischyov
Author by

Sergey Grischyov

St. Petersburg State University graduate. Cocoa Controls contributor.

Updated on October 16, 2022

Comments

  • Sergey Grischyov
    Sergey Grischyov over 1 year

    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.

  • Michal
    Michal over 10 years
    Do you have a link to the thread in the forum? In one of the WWDC videos, they are showing how nicely implemented it is, along with a sample project which fails to build, bcs the method they're using is not in the API.
  • rob mayoff
    rob mayoff over 10 years
    I have updated my answer with a link to a discussion on Apple's developer forum.
  • Rodrigo Ruiz
    Rodrigo Ruiz over 9 years
    Since iOS 8 hasn't come out yet, I need a iOS 7 solution, and yours didn't work, any idea why? stackoverflow.com/questions/25369789/…