ZBarSDK


扫描页面显示中文

1:选中项目,找Supporting Files/xxxx.plist   找Localization native development region   value设为en(设为chinese启动报错)

2:找Supporting Files/InfoPlist.strings   ,在右边的Localizations   添加Chinese

                     key                                                  type                     value
Localization native development region            (string)                    en


Localizations                                                       array                     
     item0                                                              string                    Chinese






扫描



{
    int num;
    
    BOOL upOrdown;
   
NSTimer * timer;
    
    UIButton *_BigImageView ;
}




if (button. tag == 0 ) {
       
NSLog ( @" 扫描二维码 " );
       
if ( SYSTEM_VERSION ()>= 7.0 ) {
           
AVAuthorizationStatus authStatus = [ AVCaptureDevice authorizationStatusForMediaType : AVMediaTypeVideo ]; // 获取对摄像头的访问权限。
           
if (authStatus== AVAuthorizationStatusDenied ||authStatus == AVAuthorizationStatusRestricted ) {
                [[[
UIAlertView alloc ] initWithTitle : @" 未获得授权使用摄像头 " message : @" 请去 设置 < 隐私 < 相机 ,为应用打开相机功能,再重新进入本页面! " delegate : nil cancelButtonTitle : @" 好的 " otherButtonTitles : nil ] show ];
               
return ;
            }
            [
self scanBtnAction ];
        }

-( void )scanBtnAction
{
   
num = 0 ;
   
upOrdown = NO ;
   
// 初始话 ZBar
   
ZBarReaderViewController * reader = [ ZBarReaderViewController new ];
   
// 设置代理
   
   
int i = 0 ;
   
for ( UIView *temp in [reader. view subviews ]) {
       
for ( UIView *v in [temp subviews ]) {
           
if ([v isKindOfClass :[ UIToolbar class ]]) {
               
for ( UIView *ev in [v subviews ]) {
                   
                   
if (i== 3 ) {
                        [ev
removeFromSuperview ];
                    }
                    i++;
                }
            }
        }
       
       
    }
   
ZBarReaderView *readerView;
    readerView.
torchMode = 1 ;
    reader.
readerDelegate = self ;
   
// 支持界面旋转
    reader.
supportedOrientationsMask = ZBarOrientationMaskAll ;
    reader.
showsHelpOnFail = NO ;
    reader.
scanCrop = CGRectMake ( 0.1 , 0.2 , 0.8 , 0.8 ); // 扫描的感应框
   
   
ZBarImageScanner * scanner = reader. scanner ;
    [scanner
setSymbology : ZBAR_I25
                  
config : ZBAR_CFG_ENABLE
                      
to : 0 ];
    reader.
showsZBarControls = YES ;
    reader.
tracksSymbols = YES ;
   
   
UIView * OverlayView = [[ UIView alloc ] init ];
    OverlayView.
frame = CGRectMake ( 0 , 0 , self . view . frame . size . width , self . view . frame . size . height );
    OverlayView.
frame = CGRectMake ( 0 , 0 , PDA_WIDTH , PDA_HEIGHT );
    OverlayView.
backgroundColor = [ UIColor clearColor ];
   
   
if ( SYSTEM_VERSION () < 8.0 ){
       
       
//  self.navigationController.navigationBarHidden = YES;
       
self . navigationController . navigationBar . barTintColor = [[ UIColor blackColor ] colorWithAlphaComponent : 0.4 ];
       
self . navigationController . navigationBar . translucent = NO ;
        OverlayView.
frame = CGRectMake ( 0 , 44 , self . view . frame . size . width , self . view . frame . size . height );
       
//self.edgesForExtendedLayout = UIRectEdgeAll;
    }
    reader.
cameraOverlayView = OverlayView;
   
   
UIImageView * image = [[ UIImageView alloc ] initWithImage :[ UIImage imageNamed : @"pick_bg.png" ]];
//    image.backgroundColor=[UIColor redColor];
    image.
frame = CGRectMake (( self . view . frame . size . width - 250 ) / 2 , ( self . view . frame . size . height - 250 ) / 2 , 250 , 250 );
    [OverlayView
addSubview :image];
   
UIView *view1 = [[ UIView alloc ] initWithFrame : CGRectMake (image. frame . origin . x , 0 , self . view . frame . size . width - image. frame . origin . x * 2 , image. frame . origin . y )];
    view1.
backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent : 0.4 ];
    [OverlayView
addSubview :view1];
   
UIView *view2 = [[ UIView alloc ] initWithFrame : CGRectMake ( 0 , 0 , image. frame . origin . x , self . view . frame . size . height )];
    view2.
backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent : 0.4 ];
    [OverlayView
addSubview :view2];
   
UIView *view3 = [[ UIView alloc ] initWithFrame : CGRectMake (( self . view . frame . size . width - 250 ) / 2 + image. frame . size . width , 0 , ( self . view . frame . size . width - 250 ) / 2 , self . view . frame . size . height )];
    view3.
backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent : 0.4 ];
    [OverlayView
addSubview :view3];
   
   
UIView *view4 = [[ UIView alloc ] initWithFrame : CGRectMake (image. frame . origin . x ,image. frame . origin . y + image. frame . size . height , self . view . frame . size . width - image. frame . origin . x * 2 , self . view . frame . size . height - image. frame . origin . y - image. frame . size . height )];
    view4.
backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent : 0.4 ];
    [OverlayView
addSubview :view4];
   
   
   
UILabel * label = [[ UILabel alloc ] initWithFrame : CGRectMake (- 10 , 20 , 280 , 40 )];
    label.
text = @" 请将扫描的二维码放入框内 \n 即可自动扫描 " ;
    label.
textColor = [ UIColor grayColor ];
    label.
font = [ UIFont systemFontOfSize : 15.0 ];
    label.
textAlignment = 1 ;
    label.
lineBreakMode = 0 ;
    label.
numberOfLines = 2 ;
    label.
backgroundColor = [ UIColor clearColor ];
    [view4
addSubview :label];
   
   
_line = [[ UIImageView alloc ] initWithFrame : CGRectMake ( 15 , 20 , 220 , 2 )];
   
_line . image = [ UIImage imageNamed : @"line.png" ];
    [image
addSubview : _line ];
   
// 定时器,设定时间
   
timer = [ NSTimer scheduledTimerWithTimeInterval : .01 target : self selector : @selector (animation1) userInfo : nil repeats : YES ];
   
// [self presentModalViewController:reader animated:YES];
    [
self presentViewController :reader animated : YES completion : nil ];
}


- (
void )animation1
{
   
UIImageView * image = [[ UIImageView alloc ] initWithImage :[ UIImage imageNamed : @"pick_bg.png" ]];
   
//    image.backgroundColor=[UIColor redColor];
    image.
frame = CGRectMake (( self . view . frame . size . width - 250 ) / 2 , ( self . view . frame . size . height - 250 ) / 2 , 250 , 250 );
   
   
   
if ( upOrdown == NO ) {
       
num ++;
       
_line . frame = CGRectMake ( 15 , 0 + num , 220 , 2 );
       
if ( num == 250 ) {
           
upOrdown = YES ;
        }
    }
   
else {
       
num --;
       
_line . frame = CGRectMake ( 15 , 0 + num , 220 , 2 );
       
if ( num == 0 ) {
           
upOrdown = NO ;
        }
    }
   
}

-(
void )imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo:( NSDictionary *)info
{
    [
timer invalidate ];
   
_line . frame = CGRectMake ( 0 , 0 , 250 , 2 );
   
num = 0 ;
   
upOrdown = NO ;
    [picker
dismissViewControllerAnimated : YES completion :^{
        [picker
removeFromParentViewController ];
       
UIImage * image = [info objectForKey : UIImagePickerControllerOriginalImage ];
       
// 初始化
       
ZBarReaderController * read = [ ZBarReaderController new ];
       
// 设置代理
        read.
readerDelegate = self ;
       
CGImageRef cgImageRef = image. CGImage ;
       
ZBarSymbol * symbol = nil ;
       
id < NSFastEnumeration > results = [read scanImage :cgImageRef];
       
for (symbol in results)
        {
           
break ;
        }
       
NSString * result = symbol. data ;
       
NSLog ( @"result  ==%@" ,result);
       
        [
self QRCodeShow :result];
       
       
       
       
       
    }];
     }

-(
void )imagePickerControllerDidCancel:( UIImagePickerController *)picker
{
   
if ( SYSTEM_VERSION () < 8.0 ){
       
self . navigationController . navigationBar . translucent = YES ;
       
self . navigationController . navigationBar . barTintColor = [ UIColor colorWithRed : 169.0 / 255.0 green : 184.0 / 255.0 blue : 60.0 / 255.0 alpha : 1 ];
    }
    [
timer invalidate ];
   
_line . frame = CGRectMake ( 0 , 0 , 250 , 2 );
   
num = 0 ;
   
upOrdown = NO ;
    [picker
dismissViewControllerAnimated : YES completion :^{
        [picker
removeFromParentViewController ];
    }];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值