Skip to content

Instantly share code, notes, and snippets.

@kishaningithub
Created June 4, 2015 17:51
Show Gist options
  • Save kishaningithub/0609fe899985be383a48 to your computer and use it in GitHub Desktop.
Save kishaningithub/0609fe899985be383a48 to your computer and use it in GitHub Desktop.

Revisions

  1. kishaningithub revised this gist Jun 4, 2015. No changes.
  2. kishaningithub created this gist Jun 4, 2015.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    class ViewController: UIViewController {

    var session:AVCaptureSession!

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewWillAppear(animated: Bool) {
    session = AVCaptureSession()
    session.sessionPreset = AVCaptureSessionPresetPhoto
    var inputDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    var deviceInput = AVCaptureDeviceInput.deviceInputWithDevice(inputDevice, error: nil) as! AVCaptureDeviceInput
    session.addInput(deviceInput)

    var previewLayer:AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: session)
    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

    previewLayer.frame = self.view.frame
    self.view.layer.insertSublayer(previewLayer, atIndex: 0)
    session.startRunning()
    }

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }


    }