我使用Zbar SDK并想在我的定义框架中扫描QRcode和条形码,但它是在屏幕的任何部分扫描而不是在我定义的框架中,所以我在哪里做错了?
我想在我定义的框架中进行这样的扫描。
http://www.visionsmarts.com/products/VSBarcodeReader/VSBarcodeReader.html
这是我的代码。
-(void)displayMe{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.showsZBarControls=NO;
//////////////black area/////////////////////////
UIImage *image1 = [UIImage imageNamed:@"blackscreen.png"];
UIImageView *imageLogo1 = [[UIImageView alloc] initWithImage:image1];
imageLogo1.frame = CGRectMake(0, 0, 320, 480);
cancelLabel =[[UILabel alloc]initWithFrame:CGRectMake(0,420, 320, 60)];
cancelLabel.backgroundColor = [UIColor blackColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(100,420, 100, 60)];
[btn setTitle:@"Cancel" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
btn.backgroundColor=[UIColor blackColor];
[btn addTarget:self action:@selector(back)
forControlEvents:UIControlEventTouchUpInside];
[cancelLabel bringSubviewToFront:btn];
[imageLogo1 addSubview:cancelLabel];
[imageLogo1 setUserInteractionEnabled:YES];
[imageLogo1 addSubview:btn];
//reader.cameraOverlayView = btn;
///////////////line/////////////////////////////
UIImage *image = [UIImage imageNamed:@"ScannerKitLaser@2x.png"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(40, 240, 230, 10);
[imageLogo1 addSubview:imageLogo];
///////////////Configure reader///////////////////////////////
reader.cameraOverlayView = imageLogo1;
//reader.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);
//imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
//imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 1];
ZBarCaptureReader *cap=[[ZBarCaptureReader alloc]init];
//cap.scanCrop=CGRectMake(300, 400, 230, 200);
cap.scanCrop=CGRectMake(100, 160, 50,60);
//cap.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);
[self presentModalViewController: reader
animated: YES];
[reader release];
答案 0 :(得分:3)
创建一个UIVIew(例如scanView)对象并将其作为自定义区域。你想要获得扫描区域的地方应该有透明区域或In图像透明切割。
使用此
reader.cameraOverlayView = scanView;
同时禁用除肖像模式以外的所有模式。
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
完全例如代码
在MyScanCode.h文件中
{ZBarReaderViewController *reader;}
@property (nonatomic, strong) IBOutlet UIView *scanView;
在MyScanCode.m文件中
- (void) readCode{
reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
#if !(TARGET_IPHONE_SIMULATOR)
reader.cameraOverlayView = scanView;
reader.showsZBarControls = NO;
#endif
reader.wantsFullScreenLayout = NO;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology:ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
[self presentModalViewController:reader animated:NO];
}
答案 1 :(得分:2)
尝试使用ZBarReaderView,而不是使用ZBarReaderViewController。这对我有用,节省了我很多时间。希望它能帮到你。
ZBarReaderView*reader = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader = [reader initWithImageScanner:scanner];
reader.readerDelegate = self;
reader.tracksSymbols = YES;
reader.frame = CGRectMake(20, 126-88, 283, 347);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});
[self.view addSubview:reader];