PhotographyKit 0.25

PhotographyKit 0.25

james_wolfe 维护。



  • 作者:
  • James Wolfe

PhotographyKit

A swift library for quickly integrating a built in camera session into your app.

使用cocoapods安装

pod 'PhotographyKit'

快速入门

首先创建一个PhotographyKitDelegate,这将处理捕获到的任何图像的结果

extension CameraViewController: PhotographyKitDelegate {
    
    func didCaptureImage(image: UIImage) {
        imageView.image = image
    }
    
    
    func didStartRecordingVideo() {
        print("Recording started...")
    }
    
    
    func didFinishRecordingVideo(url: URL) {
        print("Finished recording video to \(url.absoluteString)")
    }
    
    
    func didFailRecordingVideo(error: Error) {
        print("Failed recording video to \(url.absoluteString) with error: \(error.localizedDescription)")
    }
    
}

一旦设置好您的代理,您就可以初始化您的PhotographyKit对象。初始化方法需要两个参数

  • 将用于显示相机预览的视图
  • 我们上面声明的代理。
  • 请注意,如果您的PhotographyKit对象允许视频,则需要麦克风权限
do {
    camera = try PhotographyKit(view: captureView, delegate: self, allowsVideo: true)
} catch let error {
    showPhotographyKitError(error as? PhotographyKitError)
}

完成此操作后,您可以切换闪光灯、切换相机、拍照和录制视频

try? camera.takePhoto()
try? camera.startVideoRecording(maxLength: 15)
camera.endVideoRecording
try? camera.switchCamera()
try? camera.toggleFlash(.auto)