HVTCameraController Class Reference
Inherits from | UIViewController |
---|---|
Declared in | HVTCameraController.h |
Overview
The HVTCameraController operates exactly as the UIImagePickerController class of UIKit. It manages customizable, system-supplied user interfaces for taking pictures and movies on supported devices for use in your app. A camera controller manages user interactions and delivers the results of those interactions to a delegate object.
The role and appearance of the camera controller depend on the source type you assign to it before you present it.
To use the camera controller containing its default controls, perform these steps:
Check which media types are available for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.
Present the user interface by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured camera controller as the new view controller.
When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. Your delegate can then save it to the Camera Roll on the device.
You can customize an image picker controller to manage user interactions yourself. To do this, provide an overlay view containing the controls you want to display. You can display your custom overlay view in addition to, or instead of, the default controls.
Configuring the Picker
cameraDelegate
The image picker’s delegate object.
@property (nonatomic, weak) id<HVTCameraControllerDelegate> cameraDelegate
Discussion
The delegate receives notifications when the user finishes capturing an image or movie, or exits the camera interface. The delegate also decides when to dismiss the picker interface, so you must provide a delegate to use a picker.
For information about the methods you can implement for your delegate object, see HVTCameraControllerDelegate Protocol Reference.
Declared In
HVTCameraController.h
mediaTypes
An array indicating the media types to be accessed by the media picker controller.
@property (nonatomic, copy) NSArray *mediaTypes
Discussion
Depending on the media types you assign to this property, the camera controller displays a dedicated interface for still images or movies, or a selection control that lets the user choose the camera interface. Before setting this property, check which media types are available by calling the availableMediaTypesForSourceType: class method.
If you set this property to an empty array, or to an array in which none of the media types is available for the current source, the system throws an exception.
By default, this property is set to the single value kUTTypeImage, which designates the still camera interface. To designate the movie capture interface, use the kUTTypeMovie identifier in a statement like this:
myCameraController.mediaTypes = @[(NSString *) kUTTypeMovie];
Declared In
HVTCameraController.h
Configuring the Video Capture Options
videoQuality
The video recording quality expressed in resolution types.
@property (nonatomic) HVTCameraControllerQualityType videoQuality
Discussion
The video quality setting specified by this property is used during video recording.
The various video qualities are listed in the HVTCameraControllerQualityType enumeration. The default value is HVTCameraControllerQualityType1920x1080. To capture a movie using a video quality other than the default value, you must set the quality explicitly.
This property is available only if the mediaTypes property’s value array includes the kUTTypeMovie media type.
If the cameraDevice does not support the videoQuality, it will use the default value.
Declared In
HVTCameraController.h
videoMaximumDuration
The maximum duration, in seconds, for a video recording.
@property (nonatomic) NSTimeInterval videoMaximumDuration
Discussion
The default value for this property is 10 minutes (600 seconds).
This property is available only if the mediaTypes property’s value array includes the kUTTypeMovie media type.
Declared In
HVTCameraController.h
Customizing the Camera Controls
showsCameraControls
Indicates whether the camera controller displays the default camera controls.
@property (nonatomic) BOOL showsCameraControls
Discussion
The default value of this property is YES, which specifies that the default camera controls are visible in the camera controller. Set it to NO to hide the default controls if you want to instead provide a custom overlay view using the cameraOverlayView property.
Declared In
HVTCameraController.h
cameraOverlayView
The view to display on top of the default image picker interface.
@property (nonatomic, strong) UIView *cameraOverlayView
Discussion
You can use an overlay view to present a custom view hierarchy on top of the default camera interface. The camera controller layers your custom overlay view on top of the other views and positions it relative to the screen coordinates. If you have the default camera controls set to be visible, incorporate transparency into your view, or position it to avoid obscuring the underlying content.
Declared In
HVTCameraController.h
cameraViewTransform
The transform to apply to the camera’s preview image.
@property (nonatomic) CGAffineTransform cameraViewTransform
Discussion
This transform affects the live preview image only and does not affect your custom overlay view or the default camera controls. You can use this property in conjunction with custom controls to implement your own electronic zoom behaviors.
Declared In
HVTCameraController.h
Capturing Still Images or Movies
– takePicture
Captures a still image using the camera.
- (void)takePicture
Discussion
Calling this method while an image is being captured has no effect. You must wait until the associated delegate object receives an cameraController:didFinishCapturingMediaWithInfo: message before you can capture another picture.
Declared In
HVTCameraController.h
– startVideoCapture
Starts video capture using the camera specified by the UIImagePickerControllerCameraDevice property.
- (BOOL)startVideoCapture
Return Value
YES on success or NO on failure. This method may return a value of NO for various reasons, among them the following:
Movie capture is already in progress.
The camera controller’s cameraCaptureMode is set to HVTCameraControllerCameraCaptureModePhoto.
Declared In
HVTCameraController.h
– stopVideoCapture
Stops video capture.
- (void)stopVideoCapture
Discussion
After you call this method to stop video capture, the system calls the image picker delegate’s cameraController:didFinishCapturingMediaWithInfo: method.
Declared In
HVTCameraController.h
Configuring the Camera
cameraDevice
The camera used by the image picker controller.
@property (nonatomic) HVTCameraControllerCameraDevice cameraDevice
Discussion
The default is HVTCameraControllerCameraDeviceRear.
Declared In
HVTCameraController.h
+ isCameraDeviceAvailable:
Returns a Boolean value that indicates whether a given camera is available.
+ (BOOL)isCameraDeviceAvailable:(HVTCameraControllerCameraDevice)cameraDevice
Parameters
cameraDevice |
A HVTCameraControllerCameraDevice constant indicating the camera whose availability you want to check. |
---|
Return Value
YES
if the camera indicated by cameraDevice is available, or NO
if it is not available.
Declared In
HVTCameraController.h
cameraCaptureMode
The capture mode used by the camera.
@property (nonatomic) HVTCameraControllerCameraCaptureMode cameraCaptureMode
Discussion
The various capture modes are listed in the HVTCameraControllerCameraCaptureMode enumeration. The default value is HVTCameraControllerCameraCaptureModePhoto.
Declared In
HVTCameraController.h
cameraFlashMode
The flash mode used by the active camera.
@property (nonatomic) HVTCameraControllerCameraFlashMode cameraFlashMode
Discussion
The various flash modes are listed in the HVTCameraControllerCameraFlashMode enumeration. The default value is HVTCameraControllerCameraFlashModeAuto.
The value of this property specifies the behavior of the still-image flash when the value of the cameraCaptureMode property is HVTCameraControllerCameraCaptureModePhoto, and specifies the behavior of the video torch when cameraCaptureMode is HVTCameraControllerCameraCaptureModeVideo.
Declared In
HVTCameraController.h
+ isFlashAvailableForCameraDevice:
Indicates whether a given camera has flash illumination capability.
+ (BOOL)isFlashAvailableForCameraDevice:(HVTCameraControllerCameraDevice)cameraDevice
Parameters
cameraDevice |
A HVTCameraControllerCameraDevice constant indicating the camera whose flash capability you want to know. |
---|
Return Value
YES
if cameraDevice can use flash illumination, or NO
if it cannot.
Declared In
HVTCameraController.h