iOS开发笔记--自定义Zbar扫描界面

作者:朱克锋

邮箱:zhukefeng@iboxpay.com

转载请注明出处:http://blog.csdn.net/linux_zkf

这个简单的实例实在ZBarReaderViewControllerview层上再加一层用于定义自己的界面


[cpp]  view plain copy
  1. - (void)QRscan  
  2.   
  3. {  
  4.   
  5.     ZBarReaderViewController *reader = [ZBarReaderViewController new];  
  6.   
  7.     reader.readerDelegate = self;  
  8.   
  9. //非全屏  
  10.   
  11.     reader.wantsFullScreenLayout = NO;  
  12.   
  13.     //隐藏底部控制按钮  
  14.   
  15.     reader.showsZBarControls = NO;      
  16.   
  17. //设置自己定义的界面  
  18.   
  19.     [self setOverlayPickerView:reader];  
  20.   
  21.     ZBarImageScanner *scanner = reader.scanner;  
  22.   
  23.    [scanner setSymbology: ZBAR_I25  
  24.   
  25.                    config: ZBAR_CFG_ENABLE  
  26.   
  27.                        to: 0];  
  28.   
  29.     [self presentModalViewController: reader  
  30.   
  31.                             animated: YES];  
  32.   
  33.     [reader release];  
  34.   
  35. }  
  36.   
  37. - (void)setOverlayPickerView:(ZBarReaderViewController *)reader  
  38.   
  39. {  
  40.   
  41. //清除原有控件  
  42.   
  43.     for (UIView *temp in [reader.view subviews]) {          
  44.   
  45.         for (UIButton *button in [temp subviews]) {  
  46.   
  47.             if ([button isKindOfClass:[UIButton class]]) {                  
  48.   
  49.                 [button removeFromSuperview];                 
  50.   
  51.             }  
  52.   
  53.         }          
  54.   
  55.         for (UIToolbar *toolbar in [temp subviews]) {                 
  56.   
  57.             if ([toolbar isKindOfClass:[UIToolbar class]]) {                  
  58.   
  59.                 [toolbar setHidden:YES];  
  60.   
  61.                 [toolbar removeFromSuperview];  
  62.   
  63.             }  
  64.   
  65.         }  
  66.   
  67.     }  
  68.   
  69.     //画中间的基准线  
  70.   
  71.     UIView* line = [[UIView alloc] initWithFrame:CGRectMake(40, 220, 240, 1)];  
  72.   
  73.     line.backgroundColor = [UIColor redColor];  
  74.   
  75.     [reader.view addSubview:line];  
  76.   
  77.     [line release];     
  78.   
  79. //最上部view  
  80.   
  81.     UIView* upView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];  
  82.   
  83.     upView.alpha = 0.3;  
  84.   
  85.     upView.backgroundColor = [UIColor blackColor];  
  86.   
  87.     [reader.view addSubview:upView];  
  88.   
  89.     //用于说明的label  
  90.   
  91.     UILabel * labIntroudction= [[UILabel alloc] init];  
  92.   
  93.     labIntroudction.backgroundColor = [UIColor clearColor];  
  94.   
  95.     labIntroudction.frame=CGRectMake(15, 20, 290, 50);  
  96.   
  97.     labIntroudction.numberOfLines=2;     
  98.   
  99.     labIntroudction.textColor=[UIColor whiteColor];  
  100.   
  101.     labIntroudction.text=@"将二维码图像置于矩形方框内,离手机摄像头10CM左右,系统会自动识别。";  
  102.   
  103.     [upView addSubview:labIntroudction];  
  104.   
  105.     [labIntroudction release];  
  106.   
  107.     [upView release];      
  108.   
  109. //左侧的view  
  110.   
  111.     UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, 20, 280)];  
  112.   
  113.     leftView.alpha = 0.3;  
  114.   
  115.     leftView.backgroundColor = [UIColor blackColor];  
  116.   
  117.     [reader.view addSubview:leftView];  
  118.   
  119.     [leftView release];  
  120.   
  121. //右侧的view    
  122.   
  123.     UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(300, 80, 20, 280)];  
  124.   
  125.     rightView.alpha = 0.3;  
  126.   
  127.     rightView.backgroundColor = [UIColor blackColor];  
  128.   
  129.     [reader.view addSubview:rightView];  
  130.   
  131.     [rightView release];     
  132.   
  133.     //底部view  
  134.   
  135.     UIView * downView = [[UIView alloc] initWithFrame:CGRectMake(0, 360, 320, 120)];  
  136.   
  137.     downView.alpha = 0.3;  
  138.   
  139.     downView.backgroundColor = [UIColor blackColor];  
  140.   
  141.     [reader.view addSubview:downView];  
  142.   
  143.     [downView release];             
  144.   
  145.     //用于取消操作的button  
  146.   
  147.     UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];      
  148.   
  149.     cancelButton.alpha = 0.4;  
  150.   
  151.     [cancelButton setFrame:CGRectMake(20, 390, 280, 40)];   
  152.   
  153.     [cancelButton setTitle:@"取消" forState:UIControlStateNormal];  
  154.   
  155.     [cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];  
  156.   
  157.     [cancelButton addTarget:self action:@selector(dismissOverlayView:)forControlEvents:UIControlEventTouchUpInside];  
  158.   
  159.     [reader.view addSubview:cancelButton];  
  160.   
  161. }  
  162.   
  163. //取消button方法  
  164.   
  165. - (void)dismissOverlayView:(id)sender{   
  166.   
  167.     [self dismissModalViewControllerAnimated: YES];  
  168.   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值