In the Music app of the new iOS, we can see an album cover behind a view that blurs it.
How can something like that be accomplished? I've read the documentation, but did not find anything there.
In the Music app of the new iOS, we can see an album cover behind a view that blurs it.
How can something like that be accomplished? I've read the documentation, but did not find anything there.
An important supplement to @Joey's answer
This applies to a situation where you want to present a blurred-background
UIViewController
withUINavigationController
.Enjoy!
I don't think I'm allowed to post the code, but the above post mentioning the WWDC sample code is correct. Here is the link: https://developer.apple.com/downloads/index.action?name=WWDC%202013
The file you're looking for is the category on UIImage, and the method is applyLightEffect.
As I noted above in a comment, the Apple Blur has saturation and other things going on besides blur. A simple blur will not do... if you are looking to emulate their style.
Accepted answer is correct but there's an important step missing here, in case this view - for which you want blurred background - is presented using
[self presentViewController:vc animated:YES completion:nil]
By default, this will negate the blur as UIKit removes the presenter's view, which you are actually blurring. To avoid that removal, add this line before the previous one
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
Or use other
Over
styles.Custom blur scale
You can try
UIVisualEffectView
with custom setting as -Output:- for
blurEffect.setValue(1...
&blurEffect.setValue(2..
You can use
UIVisualEffectView
to achieve this effect. This is a native API that has been fine-tuned for performance and great battery life, plus it's easy to implement.Swift:
Objective-C:
If you are presenting this view controller modally to blur the underlying content, you'll need to set the modal presentation style to Over Current Context and set the background color to clear to ensure the underlying view controller will remain visible once this is presented overtop.
I decided to post a written Objective-C version from the accepted answer just to provide more options in this question..
The constraints could be removed if you want incase if you only support portrait mode or I just add a flag to this function to use them or not..