Photo - Kelmatou/iOSTools GitHub Wiki
Camera
Delegates
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)
}
Properties
weak var delegate: CameraDelegate?
var capturePosition: AVCaptureDevice.Position
Inits
init(frame: CGRect)
init?(coder aDecoder: NSCoder)
Methods
func capturePhoto()
func switchCamera()
Definitions
-
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 through func 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, then willChangeCapturePosition(_ cameraView:, newOrientation:)
.
PhotoLibrary
Methods
Definitions
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
}
}