Skip to main content

AilaCaptureView

UIView that provides a user interface with camera feed and UI elements.

Declaration

@interface AilaCaptureView : UIView
@property (nonatomic) AVLayerVideoGravity videoGravity;
- (void)resetGuidanceText;
- (void)reconnectAVCaptureSession;
- (void)displayMRZGuides:(BOOL)shouldShow;
@end

Description

This UIView subclass can be added to provide a user interface that includes the camera feed and UI elements to assist with MRZ scanning. It automatically manages the camera preview layer and provides guidance overlays.

Properties

videoGravity

Controls the videoGravity setting of the camera displayed in the view.

Type: AVLayerVideoGravity Default: AVLayerVideoGravityResizeAspect

Common values:

  • AVLayerVideoGravityResizeAspect - Preserve aspect ratio, fit within bounds
  • AVLayerVideoGravityResizeAspectFill - Preserve aspect ratio, fill bounds
  • AVLayerVideoGravityResize - Stretch to fill bounds

Methods

resetGuidanceText

Manually hides the MRZ guidance text in the center of the AilaCaptureView for a period of 5 seconds.

- (void)resetGuidanceText;

It is recommended to invoke this whenever the AilaCaptureView is displayed to the user.

displayMRZGuides

Shows or hides the MRZ guidance UI in the AilaCaptureView.

- (void)displayMRZGuides:(BOOL)shouldShow;

Parameters:

  • shouldShow - YES/true to show guides, NO/false to hide

Default: false

This allows the AilaCaptureView to be used for barcode or MRZ scanning.

reconnectAVCaptureSession

Reconnects the AVCaptureSession to the view.

- (void)reconnectAVCaptureSession;

Useful when the capture session needs to be reestablished.

Usage Example

#import <Aila/Aila.h>

@interface ViewController ()
@property (strong, nonatomic) AilaCaptureView *captureView;
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

// Create and configure capture view
self.captureView = [[AilaCaptureView alloc] initWithFrame:self.view.bounds];
self.captureView.videoGravity = AVLayerVideoGravityResizeAspectFill;

// Enable MRZ guides
[self.captureView displayMRZGuides:YES];

// Add to view hierarchy
[self.view addSubview:self.captureView];

// Configure SDK for MRZ
AilaConfiguration *config = [[AilaConfiguration alloc] init];
config.mrzMode = AilaMRZModeOn;
Aila_SetConfiguration(config);
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// Reset guidance when view appears
[self.captureView resetGuidanceText];
}

@end

See Also