DSCameraView
The DSCameraView class is used to display the camera preview and provides API to control and customize the UI. Users can also add interactable UI elements on the view, such as the torch button.
Definition
Assembly: DynamsoftCameraSDK.xcframework
@interface DSCameraView: UIView<CALayerDelegate>
- Objective-C
- Swift
@interface DSCameraView: UIView<CALayerDelegate>class CameraView: UIView {}
Attributes
| Attributes | Type | Description |
|---|---|---|
torchButtonVisible | BOOL | Set/get the visibility of the torch button. |
cameraToggleButtonVisible | BOOL | Set/get the visibility of the camera toggle button. |
scanRegionMaskVisible | BOOL | Set/get the visibility of the scan region mask. |
scanLaserVisible | BOOL | Set/get the visibility of the scan laser. |
tipConfig | DSTipConfig | Set/get the tip configurations. |
tipVisible | BOOL | Set/get the visibility of tip. |
Methods
| Method | Description |
|---|---|
initWithFrame | Create an instance of DSCameraView. |
getDrawingLayer | Get the specified DrawingLayer. |
createDrawingLayer | Create a new DrawingLayer. |
getVisibleRegionOfVideo | Get the visible region of the video streaming. |
setTorchButtonWithFrame | Add a torch button on your view. |
setCameraToggleButtonWithFrame | Add a camera toggle button on your view for switching between front and back camera. |
deleteUserDefinedDrawingLayer | Delete the specified drawing layer. |
clearUserDefinedDrawingLayers | Clear all the user-defined drawing layers. |
getAllDrawingLayers | Get all the drawing layers on the view. |
setScanRegionMaskStyle | Set the style of the scan region mask. |
updateTipMessage | Update the tip message. |
setDrawingItemClickListener | Set a DrawingItemClickListener to receive callback when DrawingItems on the view are clicked. |
torchButtonVisible
Set/get the visibility of the torch button.
- Objective-C
- Swift
@property (assign, nonatomic) BOOL torchButtonVisible;var torchButtonVisible: BOOL { get set }
cameraToggleButtonVisible
Set/get the visibility of the camera toggle button.
- Objective-C
- Swift
@property (assign, nonatomic) BOOL cameraToggleButtonVisible;var cameraToggleButtonVisible: BOOL { get set }
scanRegionMaskVisible
Set/get the visibility of the scan region mask.
- Objective-C
- Swift
@property (nonatomic, assign) BOOL scanRegionMaskVisible;var scanRegionMaskVisible: BOOL { get set }
scanLaserVisible
Set/get the visibility of the scan laser.
- Objective-C
- Swift
@property (nonatomic, assign) BOOL scanLaserVisible;var scanLaserVisible: BOOL { get set }
tipConfig
Set/get the tip configurations.
- Objective-C
- Swift
@property (assign, nonatomic) DSTipConfig * tipConfig;var tipConfig: DSTipConfig { get set }
tipVisible
Set/get the visibility of tip.
- Objective-C
- Swift
@property (assign, nonatomic) BOOL tipVisible;var tipConfig: BOOL { get set }
initWithFrame
Create an instance of DSCameraView.
- Objective-C
- Swift
- (instancetype)initWithFrame:(CGRect)frame;init(frame: CGRect)Parameters
frame: A CGRect value that defines the position of the view.
Return Value
An instance of DSCameraView.
Code Snippet
- Objective-C
- Swift
DSCameraView *cameraView = [[DSCameraView alloc] initWithFrame:frame];let cameraView = CameraView(frame: frame)
getDrawingLayer
Get the specified DrawingLayer.
- Objective-C
- Swift
- (nullable DSDrawingLayer *)getDrawingLayer:(NSUInteger)layerId;func getDrawingLayer(_ layerId: UInt) -> DSDrawingLayer?
Parameters
layerId: The ID of the layer that you want to get.
Return Value
The object of the targeting layer.
Code Snippet
- Objective-C
- Swift
DSDrawingLayer *drawingLayer = [cameraView getDrawingLayer:layerId];let drawingLayer = cameraView.getDrawingLayer(layerId)
createDrawingLayer
Create a new DSDrawingLayer.
- Objective-C
- Swift
- (DSDrawingLayer *)createDrawingLayer;func createDrawingLayer() -> DSDrawingLayerReturn Value
The object of the layer you created.
Code Snippet
- Objective-C
- Swift
DSDrawingLayer *drawingLayer = [cameraView createDrawingLayer];let drawingLayer = cameraView.createDrawingLayer()
getVisibleRegionOfVideo
Get the visible region of the video streaming.
- Objective-C
- Swift
- (DSRect *)getVisibleRegionOfVideo;func getVisibleRegionOfVideo() -> DSRectReturn Value
A DSRect object (measuredInPercentage = true) that defines the visible region of the video.
Code Snippet
- Objective-C
- Swift
DSRect *visibleRegion = [cameraView getVisibleRegionOfVideo];let visibleRegion = cameraView.getVisibleRegionOfVideo()
setTorchButtonWithFrame
Add a torch button on your view. If you are using enhanced feature - smart torch, the style of this torch button will be applied to the smart torch as well.
- Objective-C
- Swift
- (void)setTorchButtonWithFrame:(CGRect)frame torchOnImage:(UIImage* _Nullable)torchOnImage torchOffImage:(UIImage* _Nullable)torchOffImage NS_SWIFT_NAME(setTorchButton(frame:torchOnImage:torchOffImage:));func setTorchButton(_ frame: CGRect, torchOnImage: UIImage, torchOffImage: UIImage)
Parameters
frame: The place that you want to locate the torch button.
torchOnImage: The torch button image that you want to display when the torch is on.
torchOffImage: The torch button image that you want to display when the torch is off.
setCameraToggleButtonWithFrame
Add a camera toggle button on your view for switching between front and back camera.
- Objective-C
- Swift
- (void)setCameraToggleButtonWithFrame:(CGRect)frame cameraToggleImage:(UIImage* _Nullable)cameraToggleImage;func setCameraToggleButton(_ frame: CGRect, cameraToggleImage: UIImage)
Parameters
frame: The place that you want to locate the camera toggle button.
cameraToggleImage: The camera toggle button image.
deleteUserDefinedDrawingLayer
Delete the specified drawing layer.
Parameters
frame: The ID of the layer that you want to delete.
- Objective-C
- Swift
- (void)deleteUserDefinedDrawingLayer:(NSUInteger)layerId;func deleteUserDefinedDrawingLayer(_ layerId:UInt)
clearUserDefinedDrawingLayers
Clear all the user-defined drawing layers.
- Objective-C
- Swift
- (void)clearUserDefinedDrawingLayers;func deleteUserDefinedDrawingLayer()
getAllDrawingLayers
Get all the drawing layers on the view.
Return Value
All the drawing layers. The return value includes both system drawing layers and user defined drawing layers.
- Objective-C
- Swift
- (NSArray<DSDrawingLayer *>*)getAllDrawingLayers;func getAllDrawingLayers() -> [DrawingLayer]
setScanRegionMaskStyle
Set the style of the scan region mask.
- Objective-C
- Swift
- (void)setScanRegionMaskStyle:(UIColor)strokeColour strokeWidth:(CGFloat)strokeWidth surroundingColour:(UIColor)surroundingColour;func setScanRegionMaskStyle(_ strokeColour: UIColor, strokeWidth: CGFloat, surroundingColour: UIColor)
Parameters
strokeColour The stroke colour of the scan region box.
strokeWidth The width of the stroke.
surroundingColour The colour of the mask around the scan region.
updateTipMessage
Update the tip message. The new tip message will be immediately displayed on the view. Generally, tip messages are uploaded internally.
- Objective-C
- Swift
- (void)updateTipMessage:(NSString*)message;func updateTipMessage(_ message: String)
Parameters
tipMessage The new message that you want to display.
setDrawingItemClickListener
Set a DrawingItemClickListener to receive callback when DrawingItems on the view are clicked.
- Objective-C
- Swift
- (void)setDrawingItemClickListener:(nullable id<DSDrawingItemClickListener>)clickListener;func setDrawingItemClickListener(_ clickListener: DrawingItemClickListener?)
Parameters
clickListener: A protocol instance of DrawingItemClickListener.