skip to Main Content

I have a custom camera and I would like the user to take a picture in side of a view. For example, Snapchat has it where the user can take a picture inside of that QR code. What I want to do is the same thing. How do I go about this? Do I photoshop a png? Do I do this programmatically?

2

Answers


  1. Import a png file into your project which will be the overlay for your camera view. Then, on your camera view, set the cameraOverlayView property to the image file you imported like so:

    myCameraView.cameraOverlayView = UIImage(named: "test.png")
    
    Login or Signup to reply.
  2. To use camera overlay view with custom designed UI (XIB or Storyboard)

    first set imagePicker

    let imagePicker = UIImagePickerController()
    let overlay =     self.storyboard?.instantiateViewControllerWithIdentifier("OverlayViewCont")
    overlay?.view.frame = UIScreen.mainScreen().bounds
    let overlayView = overlay!.view as! OverlayView
    overlayView.imagePicker = imagePicker
    imagePicker.sourceType = .Camera
    imagePicker.showsCameraControls = false
    presentViewController(imagePicker, animated: true) {
        imagePicker.cameraOverlayView = overlayView
    }
    

    Comment this if you wanna use default controllers

    imagePicker.showsCameraControls = false
    

    Then I created an UIView subclass to handle overlayview controlle

    class OverlayView: UIView { // attache this class to the view in Story board or XIB
    
        var imagePicker: UIImagePickerController?
    
        @IBAction func capture(sender: AnyObject?){
            imagePicker?.takePicture()
        }
    }
    

    or you can use AVFoundation and create fully customized camera view. This method you can design it any way you like with out limitation of picker controller.

    check https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html

    this is in Objective C but can directly convert it to Swift easily.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search