LLSimpleCamera.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // CameraViewController.h
  3. // LLSimpleCamera
  4. //
  5. // Created by Ömer Faruk Gül on 24/10/14.
  6. // Copyright (c) 2014 Ömer Farul Gül. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import <AVFoundation/AVFoundation.h>
  10. typedef enum : NSUInteger {
  11. LLCameraPositionRear,
  12. LLCameraPositionFront
  13. } LLCameraPosition;
  14. typedef enum : NSUInteger {
  15. // The default state has to be off
  16. LLCameraFlashOff,
  17. LLCameraFlashOn,
  18. LLCameraFlashAuto
  19. } LLCameraFlash;
  20. typedef enum : NSUInteger {
  21. // The default state has to be off
  22. LLCameraMirrorOff,
  23. LLCameraMirrorOn,
  24. LLCameraMirrorAuto
  25. } LLCameraMirror;
  26. extern NSString *const LLSimpleCameraErrorDomain;
  27. typedef enum : NSUInteger {
  28. LLSimpleCameraErrorCodeCameraPermission = 10,
  29. LLSimpleCameraErrorCodeMicrophonePermission = 11,
  30. LLSimpleCameraErrorCodeSession = 12,
  31. LLSimpleCameraErrorCodeVideoNotEnabled = 13
  32. } LLSimpleCameraErrorCode;
  33. @interface LLSimpleCamera : UIViewController
  34. /**
  35. * Triggered on device change.
  36. */
  37. @property (nonatomic, copy) void (^onDeviceChange)(LLSimpleCamera *camera, AVCaptureDevice *device);
  38. /**
  39. * Triggered on any kind of error.
  40. */
  41. @property (nonatomic, copy) void (^onError)(LLSimpleCamera *camera, NSError *error);
  42. /**
  43. * Triggered when camera starts recording
  44. */
  45. @property (nonatomic, copy) void (^onStartRecording)(LLSimpleCamera* camera);
  46. /**
  47. * Camera quality, set a constants prefixed with AVCaptureSessionPreset.
  48. * Make sure to call before calling -(void)initialize method, otherwise it would be late.
  49. */
  50. @property (copy, nonatomic) NSString *cameraQuality;
  51. /**
  52. * Camera flash mode.
  53. */
  54. @property (nonatomic, readonly) LLCameraFlash flash;
  55. /**
  56. * Camera mirror mode.
  57. */
  58. @property (nonatomic) LLCameraMirror mirror;
  59. /**
  60. * Position of the camera.
  61. */
  62. @property (nonatomic) LLCameraPosition position;
  63. /**
  64. * White balance mode. Default is: AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance
  65. */
  66. @property (nonatomic) AVCaptureWhiteBalanceMode whiteBalanceMode;
  67. /**
  68. * Boolean value to indicate if the video is enabled.
  69. */
  70. @property (nonatomic, getter=isVideoEnabled) BOOL videoEnabled;
  71. /**
  72. * Boolean value to indicate if the camera is recording a video at the current moment.
  73. */
  74. @property (nonatomic, getter=isRecording) BOOL recording;
  75. /**
  76. * Boolean value to indicate if zooming is enabled.
  77. */
  78. @property (nonatomic, getter=isZoomingEnabled) BOOL zoomingEnabled;
  79. /**
  80. * Float value to set maximum scaling factor
  81. */
  82. @property (nonatomic, assign) CGFloat maxScale;
  83. /**
  84. * Fixess the orientation after the image is captured is set to Yes.
  85. * see: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload
  86. */
  87. @property (nonatomic) BOOL fixOrientationAfterCapture;
  88. /**
  89. * Set NO if you don't want ot enable user triggered focusing. Enabled by default.
  90. */
  91. @property (nonatomic) BOOL tapToFocus;
  92. /**
  93. * Set YES if you your view controller does not allow autorotation,
  94. * however you want to take the device rotation into account no matter what. Disabled by default.
  95. */
  96. @property (nonatomic) BOOL useDeviceOrientation;
  97. /**
  98. * Use this method to request camera permission before initalizing LLSimpleCamera.
  99. */
  100. + (void)requestCameraPermission:(void (^)(BOOL granted))completionBlock;
  101. /**
  102. * Use this method to request microphone permission before initalizing LLSimpleCamera.
  103. */
  104. //+ (void)requestMicrophonePermission:(void (^)(BOOL granted))completionBlock;
  105. /**
  106. * Returns an instance of LLSimpleCamera with the given quality.
  107. * Quality parameter could be any variable starting with AVCaptureSessionPreset.
  108. */
  109. - (instancetype)initWithQuality:(NSString *)quality position:(LLCameraPosition)position;
  110. /**
  111. * Starts running the camera session.
  112. */
  113. - (void)start;
  114. /**
  115. * Stops the running camera session. Needs to be called when the app doesn't show the view.
  116. */
  117. - (void)stop;
  118. /**
  119. * Capture an image.
  120. * @param onCapture a block triggered after the capturing the photo.
  121. * @param exactSeenImage If set YES, then the image is cropped to the exact size as the preview. So you get exactly what you see.
  122. * @param animationBlock you can create your own animation by playing with preview layer.
  123. */
  124. -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error))onCapture exactSeenImage:(BOOL)exactSeenImage animationBlock:(void (^)(AVCaptureVideoPreviewLayer *))animationBlock;
  125. /**
  126. * Capture an image.
  127. * @param onCapture a block triggered after the capturing the photo.
  128. * @param exactSeenImage If set YES, then the image is cropped to the exact size as the preview. So you get exactly what you see.
  129. */
  130. -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error))onCapture exactSeenImage:(BOOL)exactSeenImage;
  131. /**
  132. * Capture an image.
  133. * @param onCapture a block triggered after the capturing the photo.
  134. */
  135. -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error))onCapture;
  136. /**
  137. * Attaches the LLSimpleCamera to another view controller with a frame. It basically adds the LLSimpleCamera as a
  138. * child vc to the given vc.
  139. * @param vc A view controller.
  140. * @param frame The frame of the camera.
  141. */
  142. - (void)attachToViewController:(UIViewController *)vc withFrame:(CGRect)frame;
  143. /**
  144. * Changes the posiition of the camera (either back or front) and returns the final position.
  145. */
  146. - (LLCameraPosition)togglePosition;
  147. /**
  148. * Update the flash mode of the camera. Returns true if it is successful. Otherwise false.
  149. */
  150. - (BOOL)updateFlashMode:(LLCameraFlash)cameraFlash;
  151. /**
  152. * Checks if flash is avilable for the currently active device.
  153. */
  154. - (BOOL)isFlashAvailable;
  155. /**
  156. * Checks if torch (flash for video) is avilable for the currently active device.
  157. */
  158. - (BOOL)isTorchAvailable;
  159. /**
  160. * Alter the layer and the animation displayed when the user taps on screen.
  161. * @param layer Layer to be displayed
  162. * @param animation to be applied after the layer is shown
  163. */
  164. - (void)alterFocusBox:(CALayer *)layer animation:(CAAnimation *)animation;
  165. /**
  166. * Checks is the front camera is available.
  167. */
  168. + (BOOL)isFrontCameraAvailable;
  169. /**
  170. * Checks is the rear camera is available.
  171. */
  172. + (BOOL)isRearCameraAvailable;
  173. @end