I am using Swift to develop an iOS application with a camera feature, and it requires a blur layer above the camera view with a hole in the middle like the image shown below.
I have tried several methods, but none of them added the blur effect without covering the hole. I didn't find working solutions after spending time on Google as well.
Can anyone provide some hints on how can I only blur the non-transperant part of a png image that is attached to a image view?
Methods that I have tried:
Use the built-in iOS 8 blur effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark) let blurEffectView = UIVisualEffectView(effect: blurEffect) maskImage.addSubview(blurEffectView)
Use the "CIGaussianBlur" Filter
var imageToBlur = CIImage(image: image) var blurfilter = CIFilter(name: "CIGaussianBlur") blurfilter.setValue(imageToBlur, forKey: "inputImage") var resultImage = blurfilter.valueForKey("outputImage") as! CIImage var blurredImage = UIImage(CIImage: resultImage) self.maskImage.image = blurredImage
The visual effect that I want to have: