Right now I am building an iPhone app that requires blurring an entire UIView. How can I achieve this? I have seen this framework, but I don't think that works with UIView. Is there an alternate way to blur an UIView?
UPDATE: Check for my updated answer below, adding more relevance with the advent of iOS 7 and iOS 8.
To Make a Blur Background in React Native we will use the BlurView component from @react-native-community/blur provided by react-native-community. This is very useful if you want to make a splash screen.
In order for UIVisualEffectView to actually blur the content, its superview must be transparent. To make it transparent, change the background color of view to clear . Create a UIBlurEffect with a UIBlurEffect. Style.
This should work. I commented in the code to help you understand what's going on:
//To take advantage of CIFilters, you have to import the Core Image framework #import <CoreImage/CoreImage.h> //Get a UIImage from the UIView UIGraphicsBeginImageContext(myView.bounds.size); [myView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //Blur the UIImage with a CIFilter CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; [gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; [gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"]; CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"]; UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage]; //Place the UIImage in a UIImageView UIImageView *newView = [[UIImageView alloc] initWithFrame:self.view.bounds]; newView.image = endImage; [self.view addSubview:newView];
If you have any questions about the code, just leave it in the comments.
Note: CIGaussianBlur isn't present on iOS as of 5.1, so you must find a different way to blur the view for devices 5.x+ (Thanks to @BradLarson for this tip). The accepted answer in this question looks promising as a replacement, as does this library.
Ever since the release of iOS 7, This question has been getting a lot of hits and I thought I should follow up on what I ended up doing.
I personally blurred the picture at the time with photoshop, but there are many great third party libraries available that do dynamic and static blurring, here are a couple:
UITabBar
and applies to any view to get iOS 7's native blur: https://github.com/JagCesar/iOS-blur/ I wanted to post this because you no longer need to take screenshots of individual frames or screen.
iOS 8: With the coming release of iOS 8, Apple has included a built in blurred UIView
, UIVisualEffectView
(https://developer.apple.com/documentation/uikit/uivisualeffectview)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With