-
Notifications
You must be signed in to change notification settings - Fork 0
Photo
Antoine CLOP edited this page Nov 24, 2017
·
2 revisions
protocol CameraDelegate: class {
@objc optional func didFinishCapture(_ cameraView: CameraView, image: UIImage?)
@objc optional func didChangeCapturePosition(_ cameraView: CameraView, newOrientation: AVCaptureDevice.Position)
@objc optional func willChangeCapturePosition(_ cameraView: CameraView, newOrientation: AVCaptureDevice.Position)
}
weak var delegate: CameraDelegate?var capturePosition: AVCaptureDevice.Position
init(frame: CGRect)init?(coder aDecoder: NSCoder)
func capturePhoto()func switchCamera()
-
weak var delegate: CameraDelegate?: Camera delegate, assign it to your class to receive notifications. -
var capturePosition: AVCaptureDevice.Position: Camera currently used by CameraView (.front, .back, .unspecified). -
init(frame: CGRect): Create CameraView from a frame. -
init?(coder aDecoder: NSCoder): Create CameraView from storyboard. -
func capturePhoto(): Request camera to capture a photo. Photo will be send throughfunc didFinishCapture(_ cameraView:, image:)delegate. -
func switchCamera(): Change camera used. Double tapping on CameraView also change camera used. When switching camera,willChangeCapturePosition(_ cameraView:, newOrientation:)will first be called, thenwillChangeCapturePosition(_ cameraView:, newOrientation:).
func openPhotoLibrary()
-
func openPhotoLibrary(): Request device's photo library controller to be displayed over current UIViewController. To get image selected, copy paste this code in your UIViewController:
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
picker.dismiss(animated: true, completion: {
//image
})
}
else {
//no image
}
}