J'ai été utilisé AVCaptureDevice. Ce code de travail trouve que j'ai été utilisé dans mon application de code à barres. Ce code.
-(void)BarcodeStart
{
_highlightView = [[UIView alloc] init];
_highlightView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
_highlightView.layer.borderColor = [UIColor lightGrayColor].CGColor;
_highlightView.layer.borderWidth = 3;
[barcameraView addSubview:_highlightView];
_label = [[UILabel alloc] init];
_label.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40);
_label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
_label.backgroundColor = [UIColor colorWithWhite:0.15 alpha:0.65];
_label.textColor = [UIColor whiteColor];
_label.textAlignment = NSTextAlignmentCenter;
_label.text = @"(none)";
[self.view addSubview:_label];
//BackBtn UP side Show
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//[button addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown];
UIImageView *img = [[UIImageView alloc] init];
button.frame = CGRectMake(3,19,30,30);
img.image = [UIImage imageNamed:@"backBtnImg.png"];
[button setImage:img.image forState:UIControlStateNormal];
[_highlightView addSubview:button];
//
_session = [[AVCaptureSession alloc] init];
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
_input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
if (_input) {
[_session addInput:_input];
} else {
NSLog(@"Error: %@", error);
}
_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:_output];
_output.metadataObjectTypes = [_output availableMetadataObjectTypes];
_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
// _prevLayer.frame = CGRectMake(20, 70, 280, 280);
_prevLayer.frame = barcameraView.bounds;
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[barcameraView.layer addSublayer:_prevLayer];
[_session startRunning];
[barcameraView bringSubviewToFront:_highlightView];
[self.view bringSubviewToFront:_label];
}
C'est parfait, merci! – Randomblue