UIView+CameraBackground
将相机图层显示为任何 UIView 的背景。
功能
- 支持前后摄像头。
- 闪光灯模式:自动、开、关。
- 倒计时 计时器。
- 点击 对焦。
- 捏合 缩放。
用法
view.addCameraBackground()
// ...
view.takeCameraSnapshot( {
// animate snapshot capture
self.view.alpha = 0
UIView.animate(withDuration: 1) { self.view.alpha = 1 }
},
completion: { (capturedImage, error) -> () in
self.view.freeCameraSnapshot() // unfreeze image
// ... handle capturedImage and error
}
)
// ...
view.removeCameraBackground()
重要:请记住将 NSCameraUsageDescription
添加到您的 Info.plist
中。
布局
您可以更改相机控制(闪光灯、定时器以及前后相机的选择)的位置或完全隐藏它们。
view.addCameraBackground(
showButtons: true,
buttonMargins: UIEdgeInsets(top: 30, left: 10, bottom: 10, right: 10),
buttonsLocation: .left
)
安装
CocoaPods
pod 'CameraBackground'
旧版本
Swift版本 | CameraBackground版本 |
---|---|
4.0(Xcode 9.4) | pod 'MiniLayout', '~> 1.2.1' pod 'MultiToggleButton', '~> 1.7.1' pod 'CameraBackground', '~> 1.4.1' |
3 | pod 'MiniLayout', '~> 1.1.0' pod 'MultiToggleButton', '~> 1.5.2' pod 'CameraBackground', '~> 1.2' |
2.3 | pod 'MiniLayout', '~> 1.0.1' pod 'MultiToggleButton', '~> 1.4.0' pod 'CameraBackground', '~> 1.0.2' |
Swift软件包管理器
dependencies: [
.package(url: "https://github.com/yonat/CameraBackground", from: "1.6.6")
]