• ios中二维码的用法


      网上的例子  zbar 下载地址 http://pan.baidu.com/share/link?shareid=2652605686&uk=923776187
    1
    .新建一个工程A:view-base 2.拖动zbar框架到工程目录下 3.然后把zbar/iphone目录下的工程.xproj文件拖到A 4.在工程的Link Binary添加框架如下:

    Step1.使用ZBarSDK 需要导入的framework

    1.AVFoundation.framework

    2.CoreMedia.framework

    3.CoreVideo.framework

    4.QuartzCore.framework

    5.libiconv.dylib

    Step2.在ViewController.h 导入#import "ZBarSDK.h"

    Step3.在ViewController.h 继承 <ZBarReaderDelegate>协议

    Step4.写代码:

     
    -(IBAction) startScan  
    {  
        ZBarReaderController *reader = [[[ZBarReaderController alloc] init] autorelease];  
        reader.delegate = self;  
        reader.cameraMode = ZBarReaderControllerCameraModeSampling;  
          
        ZBarImageScanner *scanner = reader.scanner;  
        [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to:0];  
          
        [self presentModalViewController: reader animated:YES];  
          
    }  
    - (void) imagePickerController: (UIImagePickerController*) picker didFinishPickingMediaWithInfo: (NSDictionary*) info  
    {  
        UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];  
          
        id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];  
        ZBarSymbol *symbol = nil;  
          
        for(symbol in results)  
        {  
            break;  
        }  
          
        if(!symbol || !image)  
        {  
            return;  
        }  
          
        NSLog(@"symbol.data = %@", symbol.data);  
          
    //最关键的移行代码  
        self.resultLabel.text = symbol.data;  
          
        [picker dismissModalViewControllerAnimated: YES];  
    }  
    6.给.h添加<UINavigationControllerDelegate,UIImagePickerControllerDelegate>  
    辅助:  
    zbarTest02是自己研究的源代码.

    自己写的demo  记得一定要添加“ZBarSDK文件下的 libzbar.a”

    #import <UIKit/UIKit.h>
    
    #import "ZBarSDK.h"
    @interface ViewController : UIViewController<ZBarReaderDelegate>
    - (IBAction)click:(id)sender;
    
    @end
    
    #import "ViewController.h"
    
    
    @interface ViewController ()
    @property(nonatomic,retain)ZBarReaderViewController *reader;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)click:(id)sender {
       
      self.reader=[[[ZBarReaderViewController alloc] init] autorelease];
        self.reader.readerDelegate=self;
        ZBarImageScanner *scanner=self.reader.scanner;
        [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
        [self presentViewController:self.reader animated:YES completion:nil];
    ;
        
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        id<NSFastEnumeration> result=[info objectForKey:ZBarReaderControllerResults];
        ZBarSymbol *symbol=nil;
        for (symbol in result) {
            break;
            [self.reader dismissViewControllerAnimated:YES completion:nil];
        }
    }
    @end
  • 相关阅读:
    Centos 下安装php
    php 基础 PHP保留两位小数的几种方法
    php基础 php 全局变量
    php 基础 语句include和require的区别是什么?为避免多次包含同一文件,可用(?)语句代替它们?
    php 基础 获取远程连接
    php 基础 php获取前一天,前一个月,前一年的时间
    redis 基础 Redis 数据类型
    [Poj2349]Arctic Network(二分,最小生成树)
    [USACO07DEC]Sightseeing Cows(负环,0/1分数规划)
    [Tyvj2032]升降梯上(最短路)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3183655.html
Copyright © 2020-2023  润新知