AilaCaptureView
UIView that provides a user interface with camera feed and UI elements.
Declaration
- Objective-C
- Swift
@interface AilaCaptureView : UIView
@property (nonatomic) AVLayerVideoGravity videoGravity;
- (void)resetGuidanceText;
- (void)reconnectAVCaptureSession;
- (void)displayMRZGuides:(BOOL)shouldShow;
@end
class AilaCaptureView : UIView {
var videoGravity: AVLayerVideoGravity
func resetGuidanceText()
func reconnectAVCaptureSession()
func displayMRZGuides(_ shouldShow: Bool)
}
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 boundsAVLayerVideoGravityResizeAspectFill- Preserve aspect ratio, fill boundsAVLayerVideoGravityResize- Stretch to fill bounds
Methods
resetGuidanceText
Manually hides the MRZ guidance text in the center of the AilaCaptureView for a period of 5 seconds.
- Objective-C
- Swift
- (void)resetGuidanceText;
func 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.
- Objective-C
- Swift
- (void)displayMRZGuides:(BOOL)shouldShow;
func displayMRZGuides(_ shouldShow: Bool)
Parameters:
shouldShow-YES/trueto show guides,NO/falseto hide
Default: false
This allows the AilaCaptureView to be used for barcode or MRZ scanning.
reconnectAVCaptureSession
Reconnects the AVCaptureSession to the view.
- Objective-C
- Swift
- (void)reconnectAVCaptureSession;
func reconnectAVCaptureSession()
Useful when the capture session needs to be reestablished.
Usage Example
- Objective-C
- Swift
#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
import UIKit
import Aila
class ViewController: UIViewController {
private var captureView: AilaCaptureView!
override func viewDidLoad() {
super.viewDidLoad()
// Create and configure capture view
captureView = AilaCaptureView(frame: view.bounds)
captureView.videoGravity = .resizeAspectFill
// Enable MRZ guides
captureView.displayMRZGuides(true)
// Add to view hierarchy
view.addSubview(captureView)
// Configure SDK for MRZ
let config = AilaConfiguration()
config.mrzMode = .on
Aila_SetConfiguration(config)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Reset guidance when view appears
captureView.resetGuidanceText()
}
}
See Also
- Aila_GetAVCaptureSession - Get AVCaptureSession reference
- AilaMRZMode - Enable MRZ scanning
- Getting Started - MRZ scanning example