Show camera layer as a background to any UIView.
- Both front and back camera supported.
- Flash modes: auto, on, off.
- Countdown timer.
- Tap to focus.
- Pinch to zoom.
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()
Important: Remember to add NSCameraUsageDescription
to your Info.plist
.
You can change the location of the camera controls (flash, timer, and front/back camera selection) or hide them altogether:
view.addCameraBackground(
showButtons: true,
buttonMargins: UIEdgeInsets(top: 30, left: 10, bottom: 10, right: 10),
buttonsLocation: .left
)
pod 'CameraBackground'
dependencies: [
.package(url: "https://github.com/yonat/CameraBackground", from: "1.7.2")
]