我正在编写要扫描 qr 码的 iphone 应用程序。我有 QR 码库来扫描 QR 码。现在我想给我的iPhone应用程序提供二维码扫描接口。
在 Android 中,我可以使用SurfaceView
我们可以显示相机帧的视图来实现这一点。iPhone中是否有与Android中的surfaceview等效的东西?如果是这样怎么做。请给我一个教程或示例链接。
- (IBAction)TakePicture:(id)sender {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
// Insert the overlay:
imagePicker.cameraOverlayView = overlay;
// Allow editing of image ?
imagePicker.allowsImageEditing = YES;
[imagePicker setCameraDevice:
UIImagePickerControllerCameraDeviceFront];
[imagePicker setAllowsEditing:YES];
imagePicker.showsCameraControls=YES;
imagePicker.navigationBarHidden=YES;
imagePicker.toolbarHidden=YES;
imagePicker.wantsFullScreenLayout=YES;
self.library = [[ALAssetsLibrary alloc] init];
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
创建一个 UIView 类并添加此代码
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// Load the image to show in the overlay:
UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
[self addSubview:overlayGraphicView];
}
return self;
}
您也可以参考这个链接:http ://www.musicalgeometry.com/?p=821
自 iOS 7 以来,iOS 中很容易使用 QR 码检测,诀窍是告诉AVCaptureMetadataOutput
实例检测类型为 的对象AVMetadataObjectTypeQRCode
。
实时相机预览(如果您仍想使用它,可以访问像素)在 iOS 中已经存在很长时间了,最简单的AVCaptureVideoPreviewLayer
.