Latest 0.9.1
Homepage https://github.com/benhurott/BHPhotoView
License MIT
Platforms ios 10.0
Authors

A ultra simple camera viewer for UIView

Instalation

Requirements:

  • Swift 4
  • iOS 10.0+
  • XCode 9+

Using cocoapods:

target 'YouProject' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for TestCameraPod
  # this is temporary due to cocoapods publish issue.
  pod 'BHPhotoView', :git => 'https://github.com/benhurott/BHPhotoView'

end

Usage

1 – Creating Code Base

Add a UIView to your screen:

Adding UIView

Set your uiview class to BHPhotoView:

Set Custom Class

In your ViewController:

Import the lib:

import UIKit
import BHPhotoView //<-- here

class ViewController: UIViewController {

}

Link a IBOutlet from your UIView:
Linking IBOutlet

2 – Configuring for Camera

In your Info.plist project, set the Privacy - Camera Usage Description with any text you want.

Set Info PList

In your ViewController, add the BHPhotoViewDelegate:

extension ViewController: BHPhotoViewDelegate {
    func onPhotoCaptured(_ view: BHPhotoView, photo: UIImage) {
        // when photo has been taken, this method will be called.
    }

    func onPhotoCapturingError(_ view: BHPhotoView, error: BHPhotoViewError) {
        // if some error occurs, this method has been called.
    }
}

Set the delegate:

import UIKit
import BHPhotoView

class ViewController: UIViewController  {

    @IBOutlet weak var photoView: BHPhotoView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.photoView.delegate = self //<-- here
    }
}

3 – Starting and capturing from camera

To start camera, call the start method:

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

    // cameraPosition can be: .front | .back | .unspecified
    self.photoView.start(cameraPosition: .front)
}

To capture photo, call the capturePhoto method:

@IBAction func onTouchMyButton(_ sender: Any) {
    // when you call this method and photo has been taken,
    // the delegate methods will be called.
    self.photoView.capturePhoto()
}

To stop streaming, use the stop method:

@IBAction func onTouchMyButton(_ sender: Any) {
    self.photoView.stop()
}

4 – Result =)

Result

Release Notes

0.10.0

  • Feat: adding stop method.

0.9.1

  • Fix: cocoapods validation.

0.9.0: First release o/

Latest podspec

{
    "name": "BHPhotoView",
    "version": "0.9.1",
    "summary": "A ultra simple UIView for camera capturing.",
    "description": "Using your custom UIView to display camera stream and take a photo from it. Nothing more.",
    "homepage": "https://github.com/benhurott/BHPhotoView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ben-hur Santos Ott": "[email protected]"
    },
    "source": {
        "git": "https://github.com/benhurott/BHPhotoView.git",
        "tag": "0.9.1"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "BHPhotoView/BHPhotoView.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This