您的位置:首页 > 其它

ZBarReaderView 使用 设定扫描范围 整理 转载

2015-11-21 09:28 281 查看
ZBar为我们提供了两种使用方式,一种是直接调用ZBar提供的ZBarReaderViewController打开一个扫描界面,另一种方式是使用ZBar提供的可以嵌在其他视图中的ZBarReaderView,实际项目中我们更可能会使用第二种方式,这可以让我们对界面做更多的定制。

ZBar使用起来也非常简单,将ZBarSDK导入项目,在需要使用ZBar的文件中导入ZBarSDK.h头文件即可,以下是ZBarReaderView的初始化方法:

ZBarReaderView readerView = [[ZBarReaderView alloc]init];

readerView.frame = CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height - 44);

readerView.readerDelegate = self;

//关闭闪光灯

readerView.torchMode = 0;

//扫描区域

CGRect scanMaskRect = CGRectMake(60, CGRectGetMidY(readerView.frame) - 126, 200, 200);

//处理模拟器

if (TARGET_IPHONE_SIMULATOR) {

ZBarCameraSimulator *cameraSimulator

= [[ZBarCameraSimulator alloc]initWithViewController:self];

cameraSimulator.readerView = readerView;

}

[self.view addSubview:readerView];

//扫描区域计算

readerView.scanCrop = [self getScanCrop:scanMaskRect readerViewBounds:self.readerView.bounds];

[readerView start];

以上代码需要说明的有以下几点:

闪光灯设置

我不希望在扫描二维码时开启闪光灯,所以将ZBarReaderView的torchMode设为0,你可以将它设置为其他任何合适的值。

扫描区域计算

这点比较重要,我们常用的二维码扫描软件的有效扫描区域一般都是中央区域,其他部分是不进行扫描的,ZBar可以通过ZBarReaderView的scanCrop属性设置扫描区域,它的默认值是CGRect(0, 0, 1, 1),表示整个ZBarReaderView区域都是有效的扫描区域。我们需要把扫描区域坐标计算为对应的百度分数坐标,也就是以上代码中调用的getScanCrop:readerViewBounds方法,亲测没有问题,如下所示:

-(CGRect)getScanCrop:(CGRect)rect readerViewBounds:(CGRect)readerViewBounds

{

CGFloat x,y,width,height;

x = rect.origin.x / readerViewBounds.size.width;

y = rect.origin.y / readerViewBounds.size.height;

width = rect.size.width / readerViewBounds.size.width;

height = rect.size.height / readerViewBounds.size.height;

return CGRectMake(x, y, width, height);

}

PS:在网上找到很多这个方法都是将横坐标和纵坐标交叉,这样是有问题的,仔细想一下就会明白。

初始化部分完成之后,就可以调用ZBarReaderView的start方法开始扫描了,需要让你的类实现ZBarReaderViewDelegate协议,在扫描到二维码时会调用delegate的对应方法。最后,当二维码已经识别时候,可以调用ZBarReaderView的stop方法停止扫描。如下所示:

- (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image

{

for (ZBarSymbol *symbol in symbols) {

NSLog(@"%@", symbol.data);

break;

}

[self.readerView stop];

}

转自:http://blog.sina.com.cn/s/blog_b8e976830101cpr7.html

#import <UIKit/UIKit.h>

#import "ZBarSDK.h"

@interface yxpQrCode :UIViewController

@end

//

//  实现文件

//  TestProject

//

#import "yxpQrCode.h"

#define SCANVIEW_EdgeTop 40.0

#define SCANVIEW_EdgeLeft 50.0

#define TINTCOLOR_ALPHA 0.2  //浅色透明度

#define DARKCOLOR_ALPHA 0.5  //深色透明度

@interfaceyxpQrCode ()<ZBarReaderViewDelegate>

{

   UIView *_QrCodeline;

   NSTimer *_timer;

    

    //设置扫描画面

   UIView *_scanView;

   ZBarReaderView *_readerView;

}

@end

@implementation yxpQrCode

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil

{

   self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    returnself;

}

- (void)viewDidLoad

{

    [superviewDidLoad];

    

    self.title=@"扫描二维码";

    //初始化扫描界面

    [selfsetScanView];

    

     _readerView= [[ZBarReaderViewalloc]init];

    _readerView.frame =CGRectMake(0,64,VIEW_WIDTH, VIEW_HEIGHT -64);

    _readerView.tracksSymbols=NO;

    _readerView.readerDelegate =self;

    [_readerViewaddSubview:_scanView];

    //关闭闪光灯

    _readerView.torchMode =0;

    

    [self.viewaddSubview:_readerView];

    

    //扫描区域

    //readerView.scanCrop =

    

    [_readerViewstart];

    

    [selfcreateTimer];

    

}

#pragma mark -- ZBarReaderViewDelegate

-(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image

{

    constzbar_symbol_t *symbol =zbar_symbol_set_first_symbol(symbols.zbarSymbolSet);

   NSString *symbolStr = [NSStringstringWithUTF8String:zbar_symbol_get_data(symbol)];

    

    //判断是否包含 头'http:'

    NSString *regex =@"http+:[^\\s]*";

   NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@",regex];

    

    

    UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:@""message:symbolStrdelegate:nilcancelButtonTitle:@"取消"otherButtonTitles:nil];

    [alertViewshow];

    

    //判断是否包含 头'ssid:'

    NSString *ssid =@"ssid+:[^\\s]*";;

   NSPredicate *ssidPre = [NSPredicatepredicateWithFormat:@"SELF MATCHES
%@",ssid];

    

   if ([predicateevaluateWithObject:symbolStr]) {

        

    }

   elseif([ssidPreevaluateWithObject:symbolStr]){

        

       NSArray *arr = [symbolStrcomponentsSeparatedByString:@";"];

        

        NSArray * arrInfoHead = [[arrobjectAtIndex:0]componentsSeparatedByString:@":"];

        

        NSArray * arrInfoFoot = [[arrobjectAtIndex:1]componentsSeparatedByString:@":"];

        

        

        symbolStr = [NSStringstringWithFormat:@"ssid:
%@ \n password:%@",

                     [arrInfoHeadobjectAtIndex:1],[arrInfoFootobjectAtIndex:1]];

        

       UIPasteboard *pasteboard=[UIPasteboardgeneralPasteboard];

        //然后,可以使用如下代码来把一个字符串放置到剪贴板上:

        pasteboard.string = [arrInfoFootobjectAtIndex:1];

    }

    

}

//二维码的扫描区域

- (void)setScanView

{

    _scanView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,VIEW_HEIGHT-64)];

    _scanView.backgroundColor=[UIColorclearColor];

    

    //最上部view

   UIView* upView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,SCANVIEW_EdgeTop)];

    upView.alpha =TINTCOLOR_ALPHA;

    upView.backgroundColor = [UIColorblackColor];

    [_scanViewaddSubview:upView];

    

    //左侧的view

    UIView *leftView = [[UIViewalloc]initWithFrame:CGRectMake(0,SCANVIEW_EdgeTop,SCANVIEW_EdgeLeft,VIEW_WIDTH-2*SCANVIEW_EdgeLeft)];

    leftView.alpha =TINTCOLOR_ALPHA;

    leftView.backgroundColor = [UIColorblackColor];

    [_scanViewaddSubview:leftView];

    

    /******************中间扫描区域****************************/

    UIImageView *scanCropView=[[UIImageViewalloc]initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,VIEW_WIDTH-2*SCANVIEW_EdgeLeft,VIEW_WIDTH-2*SCANVIEW_EdgeLeft)];

    //scanCropView.image=[UIImage imageNamed:@""];

    

    scanCropView.layer.borderColor=[UIColorgetThemeColor].CGColor;

    scanCropView.layer.borderWidth=2.0;

    

    scanCropView.backgroundColor=[UIColorclearColor];

    [_scanViewaddSubview:scanCropView];

    

    

    //右侧的view

    UIView *rightView = [[UIViewalloc]initWithFrame:CGRectMake(VIEW_WIDTH-SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,SCANVIEW_EdgeLeft,VIEW_WIDTH-2*SCANVIEW_EdgeLeft)];

    rightView.alpha =TINTCOLOR_ALPHA;

    rightView.backgroundColor = [UIColorblackColor];

    [_scanViewaddSubview:rightView];

    

    

    //底部view

    UIView *downView = [[UIViewalloc]initWithFrame:CGRectMake(0,VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop,VIEW_WIDTH,VIEW_HEIGHT-(VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop)-64)];

    //downView.alpha = TINTCOLOR_ALPHA;

    downView.backgroundColor = [[UIColorblackColor]colorWithAlphaComponent:TINTCOLOR_ALPHA];

    [_scanViewaddSubview:downView];

    

    //用于说明的label

   UILabel *labIntroudction= [[UILabelalloc]init];

    labIntroudction.backgroundColor = [UIColorclearColor];

    labIntroudction.frame=CGRectMake(0,5,VIEW_WIDTH,20);

    labIntroudction.numberOfLines=1;

    labIntroudction.font=[UIFontsystemFontOfSize:15.0];

    labIntroudction.textAlignment=NSTextAlignmentCenter;

    labIntroudction.textColor=[UIColorwhiteColor];

    labIntroudction.text=@"将二维码对准方框,即可自动扫描";

    [downViewaddSubview:labIntroudction];

    

   UIView *darkView = [[UIViewalloc]initWithFrame:CGRectMake(0,
downView.frame.size.height-100.0,VIEW_WIDTH,100.0)];

    darkView.backgroundColor = [[UIColorblackColor] colorWithAlphaComponent:DARKCOLOR_ALPHA];

    [downViewaddSubview:darkView];

    

    //用于开关灯操作的button

   UIButton *openButton=[[UIButtonalloc]initWithFrame:CGRectMake(10,20,300.0, 40.0)];

    [openButtonsetTitle:@"开启闪光灯" forState:UIControlStateNormal];

    [openButton setTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];

    openButton.titleLabel.textAlignment=NSTextAlignmentCenter;

    openButton.backgroundColor=[UIColorgetThemeColor];

    openButton.titleLabel.font=[UIFontsystemFontOfSize:22.0];

    [openButtonaddTarget:selfaction:@selector(openLight)forControlEvents:UIControlEventTouchUpInside];

    [darkViewaddSubview:openButton];

    

    //画中间的基准线

    _QrCodeline = [[UIViewalloc]initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,VIEW_WIDTH-2*SCANVIEW_EdgeLeft,2)];

    _QrCodeline.backgroundColor = [UIColorgetThemeColor];

    [_scanViewaddSubview:_QrCodeline];

}

- (void)openLight

{

    if (_readerView.torchMode ==0)
{

        _readerView.torchMode =1;

    }else

    {

        _readerView.torchMode =0;

    }

}

- (void)viewWillDisappear:(BOOL)animated

{

    [superviewWillDisappear:animated];

    

    if (_readerView.torchMode ==1)
{

        _readerView.torchMode =0;

    }

    [selfstopTimer];

    

     [_readerViewstop];

    

}

//二维码的横线移动

- (void)moveUpAndDownLine

{

    CGFloat Y=_QrCodeline.frame.origin.y;

    //CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft, 1)]

   if (VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop==Y){

        

        [UIView beginAnimations:@"asa" context:nil];

        [UIView setAnimationDuration:1];

        _QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft,1);

        [UIView commitAnimations];

    }elseif(SCANVIEW_EdgeTop==Y){

        [UIView beginAnimations:@"asa" context:nil];

        [UIView setAnimationDuration:1];

        _QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft,1);

        [UIView commitAnimations];

    }

    

}

- (void)createTimer

{

    //创建一个时间计数

    _timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:selfselector:@selector(moveUpAndDownLine)
userInfo:nil repeats:YES];

}

- (void)stopTimer

{

   if ([_timer isValid] ==YES) {

        [_timer invalidate];

        _timer =nil;

    }

}

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

整合修改版:

//
//  ScanViewController.m
//  timeweb
//
//  Created by qf on 15/11/20.
//  Copyright © 2015年 cgb. All rights reserved.
//

#import "ScanViewController.h"
#import "CGBNavigationController.h"
#define VIEW_WIDTH SCREEN_WIDTH
#define VIEW_HEIGHT SCREEN_HEIGHT
#define SCANVIEW_EdgeTop 64+40.0
#define SCANVIEW_EdgeLeft 50.0
#define TINTCOLOR_ALPHA 0.2
//浅色透明度
#define DARKCOLOR_ALPHA 0.5
//深色透明度
#define getThemeColor greenColor
@interface ScanViewController ()< ZBarReaderViewDelegate >
{
    ZBarReaderView *_readerView;
    UIView * _scanView;
    UIView *_QrCodeline;
    NSTimer *_timer;
    UIImageView * imgView;
}
@end
@implementation ScanViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    
    self . title =
@"扫描二维码" ;
    //初始化扫描界面
    [ self setScanView ];
    _readerView = [[ ZBarReaderView alloc ] init ];
    _readerView . frame = CGRectMake ( 0 ,
0 , VIEW_WIDTH , VIEW_HEIGHT );
    _readerView . tracksSymbols = NO ;
    _readerView . readerDelegate = self ;
    [ _readerView addSubview : _scanView ];
    //关闭闪光灯
    _readerView . torchMode = 0 ;
    [ self . view addSubview : _readerView ];
    //扫描区域
    //CGRect scanMaskRect = CGRectMake(60, CGRectGetMidY(_readerView.frame) - 126, 200, 200);
    //_readerView.scanCrop =  CGRectMake(0, 0, 1, 1);
    [ _readerView start ];
    [self back];
    [self createTimer];
}

- (void)back{
    UIImageView * imgView = [[UIImageView alloc]init];
    imgView.image = [UIImage imageNamed:@"menu_top_bg7"];
    [self.view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(64);
        make.width.mas_equalTo(self.view.mas_width);
        make.top.equalTo(self.view.mas_top);
    }];
    
    UIButton * leftButton = [Common addCustomButtonWithFrame:CGRectMake(15,
30, 50,
20) title:@"返回" image:[UIImage imageNamed:@"icon_index_selectcity"]
bgImage:nil tag:100 target:self action:@selector(leftButtonClick:)];
    [leftButton setImage:[UIImage imageNamed:@"icon_index_selectcity"] forState:UIControlStateHighlighted];
    
    leftButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    leftButton.titleLabel.font = [UIFont systemFontOfSize:16];
    leftButton.titleEdgeInsets = UIEdgeInsetsMake(0, -35,
0, 0);
    leftButton.imageEdgeInsets = UIEdgeInsetsMake(0,
0, 0, -60);
    [self.view addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(20);
        make.top.mas_equalTo(self.view.mas_top).offset(30);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
    }];

}

- (void)leftButtonClick:(UIButton *)btn{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(CGRect)getScanCrop:(CGRect)rect readerViewBounds:(CGRect)readerViewBounds
{
    CGFloat x,y,width,height;
    
    x = rect.origin.x / readerViewBounds.size.width;
    y = rect.origin.y / readerViewBounds.size.height;
    width = rect.size.width / readerViewBounds.size.width;
    height = rect.size.height / readerViewBounds.size.height;
    
    return CGRectMake(x, y, width, height);
}
- ( void )setScanView
{
    
    _scanView =[[ UIView alloc ] initWithFrame : CGRectMake (
0 , 0 , VIEW_WIDTH , SCREEN_HEIGHT )];
    _scanView . backgroundColor =[ UIColor clearColor ];
    //最上部view
    UIView * upView = [[ UIView alloc ] initWithFrame : CGRectMake (
0 , 64 , VIEW_WIDTH , SCANVIEW_EdgeTop )];
    upView. alpha = TINTCOLOR_ALPHA ;
    upView. backgroundColor = [ UIColor blackColor ];
    [ _scanView addSubview :upView];
    //左侧的view
    UIView *leftView = [[ UIView alloc ] initWithFrame : CGRectMake (
0 , SCANVIEW_EdgeTop +64, SCANVIEW_EdgeLeft , VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft )];
    leftView. alpha = TINTCOLOR_ALPHA ;
    leftView. backgroundColor = [ UIColor blackColor ];
    [ _scanView addSubview :leftView];
    /******************中间扫描区域****************************/
    UIImageView *scanCropView=[[ UIImageView alloc ] initWithFrame : CGRectMake ( SCANVIEW_EdgeLeft , SCANVIEW_EdgeTop +64, VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft , VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft )];
    //scanCropView.image=[UIImage imageNamed:@""];
    scanCropView. layer . borderColor =[ UIColor getThemeColor].CGColor ;
    scanCropView. layer . borderWidth = 2.0 ;
    scanCropView. backgroundColor =[ UIColor clearColor ];
    imgView = scanCropView;
    [ _scanView addSubview :scanCropView];
    //右侧的view
    UIView *rightView = [[ UIView alloc ] initWithFrame : CGRectMake ( VIEW_WIDTH - SCANVIEW_EdgeLeft , SCANVIEW_EdgeTop+64 , SCANVIEW_EdgeLeft , VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft )];
    rightView. alpha = TINTCOLOR_ALPHA ;
    rightView. backgroundColor = [ UIColor blackColor ];
    [ _scanView addSubview :rightView];
    //底部view
    UIView *downView = [[ UIView alloc ] initWithFrame : CGRectMake (
0 , VIEW_WIDTH - 2 * SCANVIEW_EdgeLeft + SCANVIEW_EdgeTop +64, VIEW_WIDTH , SCREEN_HEIGHT -( VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft + SCANVIEW_EdgeTop )-64 )];
    //downView.alpha = TINTCOLOR_ALPHA;
    downView. backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent : TINTCOLOR_ALPHA ];
    [ _scanView addSubview :downView];
    //用于说明的label
    UILabel *labIntroudction= [[ UILabel alloc ] init ];
    labIntroudction. backgroundColor = [ UIColor clearColor ];
    labIntroudction. frame = CGRectMake ( 0 ,
5 , VIEW_WIDTH , 20 );
    labIntroudction. numberOfLines = 1 ;
    labIntroudction. font =[ UIFont systemFontOfSize :
15.0 ];
    labIntroudction. textAlignment = NSTextAlignmentCenter ;
    labIntroudction. textColor =[ UIColor whiteColor ];
    labIntroudction. text = @"将二维码对准方框,即可自动扫描" ;
    [downView addSubview :labIntroudction];
    UIView *darkView = [[ UIView alloc ] initWithFrame : CGRectMake (
0 , downView. frame . size . height -
100.0 , VIEW_WIDTH , 100.0 )];
    darkView. backgroundColor = [[ UIColor blackColor ]  colorWithAlphaComponent : DARKCOLOR_ALPHA ];
    [downView addSubview :darkView];
    //用于开关灯操作的button
    UIButton *openButton=[[ UIButton alloc ] initWithFrame : CGRectMake (
10 , 20 ,
300.0 , 40.0 )];
    [openButton setTitle : @"开启闪光灯" forState: UIControlStateNormal ];
    [openButton setTitleColor :[ UIColor whiteColor ] forState : UIControlStateNormal ];
    openButton. titleLabel . textAlignment = NSTextAlignmentCenter ;
    openButton. backgroundColor =[ UIColor getThemeColor ];
    openButton. titleLabel . font =[ UIFont systemFontOfSize :
22.0 ];
    [openButton addTarget : self action :
@selector (openLight) forControlEvents : UIControlEventTouchUpInside ];
    [darkView addSubview :openButton];
    _QrCodeline = [[ UIView alloc ] initWithFrame : CGRectMake ( SCANVIEW_EdgeLeft , SCANVIEW_EdgeTop +64 , VIEW_WIDTH -
2 * SCANVIEW_EdgeLeft , 2 )];
    _QrCodeline . backgroundColor = [ UIColor getThemeColor ];
    [ _scanView addSubview : _QrCodeline ];
}
- ( void )openLight
{
    if ( _readerView . torchMode ==
0 ) {
        _readerView . torchMode = 1 ;
    } else
    {
        _readerView . torchMode = 0 ;
    }
}

-( void )readerView:( ZBarReaderView *)readerView didReadSymbols:( ZBarSymbolSet *)symbols fromImage:( UIImage *)image
{
    const zbar_symbol_t *symbol = zbar_symbol_set_first_symbol (symbols. zbarSymbolSet );
    NSString *symbolStr = [ NSString stringWithUTF8String : zbar_symbol_get_data (symbol)];
    //判断是否包含
头'http:'
    NSString *regex = @"http+:[^//s]*" ;
    NSPredicate *predicate = [ NSPredicate predicateWithFormat :
@"SELF MATCHES %@" ,regex];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:symbolStr]];
    //判断是否包含
头'ssid:'
    NSString *ssid = @"ssid+:[^//s]*" ;;
    NSPredicate *ssidPre = [ NSPredicate predicateWithFormat :
@"SELF MATCHES %@" ,ssid];
    if ([predicate evaluateWithObject :symbolStr]) {
    }
    else
if ([ssidPre evaluateWithObject :symbolStr]){
        NSArray *arr = [symbolStr componentsSeparatedByString :
@";" ];
        NSArray * arrInfoHead = [[arr objectAtIndex :
0 ] componentsSeparatedByString :
@":" ];
        NSArray * arrInfoFoot = [[arr objectAtIndex :
1 ] componentsSeparatedByString :
@":" ];
        symbolStr = [ NSString stringWithFormat :
@"ssid: %@ /n password:%@" ,
                     [arrInfoHead objectAtIndex :
1 ],[arrInfoFoot objectAtIndex :
1 ]];
        UIPasteboard *pasteboard=[ UIPasteboard generalPasteboard ];
        //然后,可以使用如下代码来把一个字符串放置到剪贴板上:
        pasteboard. string = [arrInfoFoot objectAtIndex :
1 ];
    }
}
- (void)moveUpAndDownLine
{
    CGFloat Y=_QrCodeline.frame.origin.y;
    //CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft, 1)]
    CGFloat Y2=imgView.frame.origin.y;
    CGFloat Y3=imgView.frame.origin.y+imgView.frame.size.height;
    CGRect frame = _QrCodeline.frame;
    if (Y3 <= Y){
        
        [UIView beginAnimations:@"asa" context:nil];
        [UIView setAnimationDuration:1];
//        _QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft,1);
        frame.origin.y = Y2;
        _QrCodeline.frame = frame;
        
        [UIView
commitAnimations];
    }else
if(Y2 >= Y){
        [UIView
beginAnimations:@"asa"
context:nil];
        [UIView
setAnimationDuration:1];
        frame.origin.y = Y3;
        _QrCodeline.frame = frame;
//        _QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft,1);
        [UIView
commitAnimations];
    }
    
}

- (void)createTimer
{
    //创建一个时间计数
    _timer=[NSTimer
scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(moveUpAndDownLine)
userInfo:nil
repeats:YES];
}

- (void)stopTimer
{
    if ([_timer
isValid] ==YES) {
        [_timer
invalidate];
        _timer =nil;
    }
}
- ( void )viewWillDisappear:(
BOOL )animated
{
    [ super
viewWillDisappear :animated];
    if (_readerView .
torchMode == 1 ) {
        _readerView .
torchMode = 0 ;
    }

    [self
stopTimer];
    [_readerView
stop];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return
UIStatusBarStyleLightContent;
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: