zbar 自定义扫描界面
2018年08月22日
⁄ 综合
⁄ 共 3584字 ⁄ 字号
小 中 大
- - (void)QRscan
-
- {
-
- ZBarReaderViewController *reader = [ZBarReaderViewController new];
-
- reader.readerDelegate = self;
-
-
-
- reader.wantsFullScreenLayout = NO;
-
-
-
- reader.showsZBarControls = NO;
-
-
-
- [self setOverlayPickerView:reader];
-
- ZBarImageScanner *scanner = reader.scanner;
-
- [scanner setSymbology: ZBAR_I25
-
- config: ZBAR_CFG_ENABLE
-
- to: 0];
-
- [self presentModalViewController: reader
-
- animated: YES];
-
- [reader release];
-
- }
-
- - (void)setOverlayPickerView:(ZBarReaderViewController *)reader
-
- {
-
-
-
- for (UIView *temp in [reader.view subviews]) {
-
- for (UIButton *button in [temp subviews]) {
-
- if ([button isKindOfClass:[UIButton class]]) {
-
- [button removeFromSuperview];
-
- }
-
- }
-
- for (UIToolbar *toolbar in [temp subviews]) {
-
- if ([toolbar isKindOfClass:[UIToolbar class]]) {
-
- [toolbar setHidden:YES];
-
- [toolbar removeFromSuperview];
-
- }
-
- }
-
- }
-
-
-
- UIView* line = [[UIView alloc] initWithFrame:CGRectMake(40, 220, 240, 1)];
-
- line.backgroundColor = [UIColor redColor];
-
- [reader.view addSubview:line];
-
- [line release];
-
-
-
- UIView* upView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
-
- upView.alpha = 0.3;
-
- upView.backgroundColor = [UIColor blackColor];
-
- [reader.view addSubview:upView];
-
-
-
- UILabel * labIntroudction= [[UILabel alloc] init];
-
- labIntroudction.backgroundColor = [UIColor clearColor];
-
- labIntroudction.frame=CGRectMake(15, 20, 290, 50);
-
- labIntroudction.numberOfLines=2;
-
- labIntroudction.textColor=[UIColor whiteColor];
-
- labIntroudction.text=@"将二维码图像置于矩形方框内,离手机摄像头10CM左右,系统会自动识别。";
-
- [upView addSubview:labIntroudction];
-
- [labIntroudction release];
-
- [upView release];
-
-
-
- UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, 20, 280)];
-
- leftView.alpha = 0.3;
-
- leftView.backgroundColor = [UIColor blackColor];
-
- [reader.view addSubview:leftView];
-
- [leftView release];
-
-
-
- UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(300, 80, 20, 280)];
-
- rightView.alpha = 0.3;
-
- rightView.backgroundColor = [UIColor blackColor];
-
- [reader.view addSubview:rightView];
-
- [rightView release];
-
-
-
- UIView * downView = [[UIView alloc] initWithFrame:CGRectMake(0, 360, 320, 120)];
-
- downView.alpha = 0.3;
-
- downView.backgroundColor = [UIColor blackColor];
-
- [reader.view addSubview:downView];
-
- [downView release];
-
-
-
- UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
-
- cancelButton.alpha = 0.4;
-
- [cancelButton setFrame:CGRectMake(20, 390, 280, 40)];
-
- [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
-
- [cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
-
- [cancelButton addTarget:self action:@selector(dismissOverlayView:)forControlEvents:UIControlEventTouchUpInside];
-
- [reader.view addSubview:cancelButton];
-
- }
-
-
-
- - (void)dismissOverlayView:(id)sender{
-
- [self dismissModalViewControllerAnimated: YES];
-
- }