DKCamera 1.6.7

DKCamera 1.6.7

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最新版本2020年3月
SPM支持 SPM

Bannings维护。



DKCamera 1.6.7

  • 作者:
  • Bannings

DKCamera

Build Status Version Status license MIT Carthage compatible


描述

一款轻量级、简单易用、iOS上的Swift相机。使用CoreMotion框架检测设备方向,因此将忽略屏幕方向锁定(完美处理方向)。它还有两个其他目的

  • 可以是显示、推送或集成。
  • 压制警告 "Taking a snapshot of a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates."(似乎是iOS 8中的一个bug)。
  • 兼容iOS 11和iPhone X

要求

  • Xcode 9
  • Swift 3.2 & 4.2

安装

iOS 8及更高版本

DKCamera可在CocoaPods中获取。只需将以下行添加到您的podfile中:

# For latest release in cocoapods
pod 'DKCamera'

iOS 7.x

请使用1.2.11标签。要在支持iOS 7的应用程序中使用Swift库,您必须手动将文件复制到您的应用程序项目中。CocoaPods仅支持在OS X 10.9和更高版本以及iOS 8和更高版本上运行Swift。

易于使用

let camera = DKCamera()

camera.didCancel = {
	print("didCancel")

	self.dismiss(animated: true, completion: nil)
}

camera.didFinishCapturingImage = { (image: UIImage?, metadata: [AnyHashable : Any]?) in
    print("didFinishCapturingImage")
    
    self.dismiss(animated: true, completion: nil)
    
    self.imageView?.image = image
}

self.present(camera, animated: true, completion: nil)

您还可以使用这些API

open var cameraOverlayView: UIView?

/// The flashModel will to be remembered to next use.
open var flashMode:AVCaptureFlashMode!

open class func isAvailable() -> Bool

/// Determines whether or not the rotation is enabled.
open var allowsRotate = false

/// set to NO to hide all standard camera UI. default is YES.
open var showsCameraControls = true

open var defaultCaptureDevice = DKCameraDeviceSourceType.rear

/// Photos will be tagged with the location where they are taken.
/// Must add the "Privacy - Location XXX" tag to your Info.plist.
open var containsGPSInMetadata = false

/// Notify the listener of the detected faces in the preview frame.
open var onFaceDetection: ((_ faces: [AVMetadataFaceObject]) -> Void)?

如果您打算添加`cameraOverlayView`的全屏视图,也许应该使用`DKCameraPassthroughView`或其子类,它已经覆盖了`hitTest`方法,以便事件传递到预期的视图。

//  DKCamera.swift
public class DKCameraPassthroughView: UIView {
	public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
		let hitTestingView = super.hitTest(point, withEvent: event)
		return hitTestingView == self ? nil : hitTestingView
	}
}

许可协议

DKCamera在MIT许可协议下发布。有关详情,请参阅LICENSE。