关于ZBarReaderView 自定义UI界面

<!-- lang: cpp -->
在此输入代码

-(void)scanClick:(id)sender
{
// [appDelegate runUI:VIEW_SCAN_VIEW];

NSLog(@" 跳转扫描扫描页面 ");

if(!self.zBarReaderView)
{
    self.zBarReaderView = [ZBarReaderViewController new];
    self.zBarReaderView.readerDelegate = self;
    self.zBarReaderView.supportedOrientationsMask = ZBarOrientationMaskAll;
    self.zBarReaderView.showsZBarControls = NO;
    self.zBarReaderView.readerView.torchMode = 0;
    [self setOverlayPickerView:self.zBarReaderView];

    ZBarImageScanner *scanner = self.zBarReaderView.scanner;
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

}

[self presentViewController:self.zBarReaderView
                   animated:YES
                 completion:^(void)
                {
                     // Code
                     NSLog(@"弹出。。。。");
                 }];

}

/**

  • 扫条形码结果
    **/

  • (void) imagePickerController: (UIImagePickerController) reader
    didFinishPickingMediaWithInfo: (NSDictionary
    ) info
    {
    id results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)

    break;
    

    //判断是否包含 头'http:'
    NSString regex = @“http+:[^\s]“;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@“SELF MATCHES %@“,regex];

    //判断是否包含 头'ssid:'
    NSString ssid = @“ssid+:[^\s]“;;
    NSPredicate ssidPre = [NSPredicate predicateWithFormat:@“SELF MATCHES %@“,ssid];
    NSString
    dataStr = symbol.data ;
    NSLog(@“ssidPre %@“, ssidPre);
    NSLog(@“predicate %@“, predicate);
    NSLog(@“dataStr %@“, dataStr);

    [self performSelector:@selector(disposeViewControl) withObject:FALSE afterDelay:5.0];
    }

/*
关闭页面
*/
-(void)disposeViewControl
{

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(disposeViewControl) object:nil];
[self dismissViewControllerAnimated:YES
                      completion:^(void)
                      {
                          NSLog(@"消失~~ ");
                       }];

}

  • (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];
        }
    }  
    

    }
    //TITLE_HEIGHT : 64 头部高度
    tmpHeight = appDelegate.mainRootView.getRootHeight - 3TITLE_HEIGHT;
    tmpWidth = appDelegate.mainRootView.getRootWidth - 30;
    //最上部view
    UIView
    upView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, appDelegate.mainRootView.getRootWidth, TITLE_HEIGHT)];
    upView.alpha = 0.4;
    upView.backgroundColor = [UIColor blackColor];
    [reader.view addSubview:upView];

    //左侧的view
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, TITLE_HEIGHT, 15, tmpHeight)];
    leftView.alpha = 0.4;
    leftView.backgroundColor = [UIColor blackColor];
    [reader.view addSubview:leftView];

    //右侧的view
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(appDelegate.mainRootView.getRootWidth - 15, TITLE_HEIGHT, 15, tmpHeight)];
    rightView.alpha = 0.4;
    rightView.backgroundColor = [UIColor blackColor];
    [reader.view addSubview:rightView];

    //底部view
    UIView * downView = [[UIView alloc] initWithFrame:CGRectMake(0, tmpHeight + TITLE_HEIGHT, appDelegate.mainRootView.getRootWidth, 2*TITLE_HEIGHT)];
    downView.alpha = 0.4;
    downView.backgroundColor = [UIColor blackColor];
    [reader.view addSubview:downView];

    //最上层的操作 左边
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(15, 24, 30, 30);
    [button setBackgroundImage:[UIImage imageNamed:@“ocrBack”] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(leftClick:) forControlEvents:UIControlEventTouchUpInside];
    [reader.view addSubview:button];

    //右边
    UIButton * buttonRight = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonRight.frame= CGRectMake(appDelegate.mainRootView.getRootWidth - 45, 24, 30, 30);
    [buttonRight setBackgroundImage:[UIImage imageNamed:@“ocr_flash_off”] forState:UIControlStateNormal];
    [buttonRight addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    [reader.view addSubview:buttonRight];

    //用于说明的label
    UILabel * labIntroudction= [[UILabel alloc] init];
    labIntroudction.backgroundColor = [UIColor clearColor];
    labIntroudction.frame=CGRectMake(0, 20, downView.frame.size.width, 50);
    labIntroudction.numberOfLines=2;
    labIntroudction.textColor=[UIColor whiteColor];
    labIntroudction.textAlignment = NSTextAlignmentCenter;
    labIntroudction.text=@“将二维码/条形码放入扫描框内\n自动识别不安全连接,请放心扫描”;
    [downView addSubview:labIntroudction];

    //4个角
    //左上
    UIImageView *leftUp=[[UIImageView alloc] initWithFrame:CGRectMake(13, TITLE_HEIGHT-2, 19, 19)];
    [leftUp setImage:[UIImage imageNamed:@“scan_1”]];
    [reader.view addSubview:leftUp];

    //右上
    UIImageView rightUp=[[UIImageView alloc] initWithFrame:CGRectMake(appDelegate.mainRootView.getRootWidth-13-19, TITLE_HEIGHT-2, 19, 19)];
    [rightUp setImage:[UIImage imageNamed:@“scan_2”]];
    [reader.view addSubview:rightUp];
    //左下
    UIImageView
    leftDown=[[UIImageView alloc] initWithFrame:CGRectMake(13, TITLE_HEIGHT+tmpHeight-15, 19, 19)];
    [leftDown setImage:[UIImage imageNamed:@“scan_3”]];
    [reader.view addSubview:leftDown];
    //右下
    UIImageView *rightDown=[[UIImageView alloc] initWithFrame:CGRectMake(appDelegate.mainRootView.getRootWidth-13-19, TITLE_HEIGHT+tmpHeight-15, 19, 19)];
    [rightDown setImage:[UIImage imageNamed:@“scan_4”]];
    [reader.view addSubview:rightDown];

    //滑动
    num =0;
    UIImage *image =[UIImage imageNamed:@“scan_net”];
    NSLog(@“image %f”, image.size.height);
    NSLog(@“image %f”, image.size.width);
    startY= TITLE_HEIGHT;
    scanNet = [[UIImageView alloc] initWithFrame:CGRectMake(15, startY, tmpWidth, tmpHeight)];
    scanNet.image = image;
    [reader.view addSubview:scanNet];
    // scanNet.layer.borderColor = [UIColor redColor].CGColor;
    // scanNet.layer.borderWidth = 1.0f;
    timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(animation1) userInfo:nil repeats:YES];

}
-(void)animation1
{

num ++;
scanNet.frame = CGRectMake(scanNet.frame.origin.x, startY, scanNet.frame.size.width,2*num);
if (2*num == tmpHeight)
{
   num = 0;
}

}

-(void) leftClick:(id)sender
{

[self disposeViewControl];

}

-(void) rightClick:(id)sender
{

UIButton *btn = (UIButton *)sender;
if (btn.selected)
{
    btn.selected = NO;
    self.zBarReaderView.readerView.torchMode = 0;
}
else
{
    btn.selected = YES;
    self.zBarReaderView.readerView.torchMode = 1;
}

}

你可能感兴趣的:(二维码扫描自定义界面)