BHPhotoView 0.12.3

BHPhotoView 0.12.3

Ben-hur Santos Ott 维护。



  • Ben-hur Santos Ott

BHPhotoView

一个超简单的 UIView 摄像头查看器

安装

要求

  • Swift 4
  • iOS 10.0+
  • XCode 9+

使用 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

用法

1 - 创建代码库

将 UIView 添加到您的屏幕上

Adding UIView


将您的 uiview 类设置为 `BHPhotoView`

Set Custom Class


在您的 `ViewController` 中

导入库

import UIKit
import BHPhotoView //<-- here

class ViewController: UIViewController {

}

从您的 UIView 链接一个 IBOutletLinking IBOutlet

2 - 为相机配置

在您的 Info.plist 项目中,设置任何您想要的文本到 隐私 - 相机使用描述

Set Info PList

在您的 ViewController 中,添加 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.
    }
}

设置代理和相机位置。

import UIKit
import BHPhotoView

class ViewController: UIViewController  {

    @IBOutlet weak var photoView: BHPhotoView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.photoView.delegate = self
        self.photoView.cameraPosition = .front
    }
}

(可选)设置预览方向。

import UIKit
import BHPhotoView

class ViewController: UIViewController  {

    @IBOutlet weak var photoView: BHPhotoView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.photoView.delegate = self
        self.photoView.cameraPosition = .front

        self.photoView.previewOrientation = AVCaptureVideoOrientation.landscapeLeft
    }
}

3 - 从相机开始和捕获

要启动相机,调用 start 方法。

override func viewDidLoad() {
    super.viewDidLoad()
    
    self.photoView.delegate = self
    self.photoView.cameraPosition = .front

    self.photoView.start()
}

要捕获照片,调用 capturePhoto 方法。

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

要停止流媒体,使用 stop 方法。

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

4 - 结果 =)

Result

高级

如果您想使用一些“高级”功能,请查阅 高级文档

版本说明

0.12.3

  • 修复:相机位置 didSet 后重新加载配置。

破坏性更改

  • 默认相机位置现在是 .back

0.12.2

  • 修复:公开 frame: 构造函数。

0.12.1

  • 修复:修复重复使用照片设置时崩溃的问题。

破坏性更改

  • 非默认闪光模式是 关闭

0.12.0

  • 特性:公开属性
    • 现在公开了更多属性 =)。

0.11.0

  • 特性:自定义
    • 现在您可以访问一些内部属性以进行高级自定义。

破坏性更改

  • 方法 .start(cameraPosition: .front) 现在是 .start()
  • 已删除方法 .capturePhoto(usingSettings: photoSettings)。请设置属性 .photoSettings

0.10.0

  • 特性:添加 stop 方法。

0.9.1

  • 修复:cocoapods 验证。

0.9.0: 首次发布 o/