为什么当我结合 UIImagview 时我的模糊视图变得透明?

Why my does blur view become transparent when I combine with UIImagview?

我有结合 UIImageView 的模糊效果。我遇到的问题是当我拍照时模糊效果变得透明并且在渲染之前看起来不一样。为什么会这样?

@IBAction func pictureButton(_ sender: Any) {
    let settings = AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])
    stillImageOutput.capturePhoto(with: settings, delegate: self)


}

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

    guard let imageData = photo.fileDataRepresentation()
        else { return }

    let image = UIImage(data: imageData)

    capturedImage.image = image

    UIGraphicsBeginImageContextWithOptions(self.capturedImage.bounds.size, false, 0.0)
    self.capturedImage.layer.render(in: UIGraphicsGetCurrentContext()!)
    self.previewView.blurEffectView.layer.render(in: UIGraphicsGetCurrentContext()!)
    let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()

    self.capturedImage.image = newImage
}

终于成功了:

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

    guard let imageData = photo.fileDataRepresentation()
        else { return }

    let image = UIImage(data: imageData)
    capturedImage.image = image


    let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
    let image2 = renderer.image { ctx in
        view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
    }
    self.capturedImage.image = image2
}