Trying to capture still image while tap on UIView.

Project from:

FaceDetectorDemo > FaceDetector > CameraViewController.m

I converted the Face detector project from objective c to swift, but I need to add an additional feature which user tap on the screen to capture but just couldn't figure it out ..

My code:

@IBOutlet weak var placeholder: UIView! 
var stillImageOutput = AVCaptureStillImageOutput()

for face in faces
  //somewhere in here called faceDetected() method

func faceDetected() -> Void
    let tapped = UITapGestureRecognizer(target:self,action:#selector(saveToCamera))      
    placeholder.isUserInteractionEnabled = true

@objc func saveToCamera(_ sender: UIGestureRecognizer)
    if let videoConnection = stillImageOutput.connection(with: {
        stillImageOutput.captureStillImageAsynchronously(from: videoConnection) {
            (imageDataSampleBuffer, error) -> Void in
            let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer!)
            UIImageWriteToSavedPhotosAlbum(UIImage(data: imageData!)!, nil, nil, nil)

It doesn't seem run into the saveToCamera while tapping on the UIView, I'm fairly new to IOS dev, need some guidance. Thanks in advanced.

Related posts

Recent Viewed