IOS 使用 ZbarSDK 二維碼掃描

來源:互聯網
上載者:User

標籤:logs   reads   after   set   ras   bar   elf   view   blog   

1. 下載SDK   https://github.com/bmorton/ZBarSDK

2. 引用到項目中

3. 添加引用

4. AppDelegate中添加下面代碼

 

5. 在需要使用掃描的controller中實現ZBarReaderViewDelegate

6. 對應的m檔案中

#import "ViewController.h"    @interface ViewController ()  {      UITextField *resultText;      ZBarReaderView *readerView;      ZBarCameraSimulator *cameraSim;  }  @end    @implementation ViewController    - (void)viewDidLoad {      [super viewDidLoad];      // Do any additional setup after loading the view, typically from a nib.            resultText = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 200, 60)];      resultText.backgroundColor = [UIColor blueColor];      [self.view addSubview:resultText];            readerView = [[ZBarReaderView alloc]init];      readerView.frame = CGRectMake(10, 110, 300, 300);      readerView.readerDelegate = self;      //關閉閃光燈      readerView.torchMode = 0;      //處理模擬器      if (TARGET_IPHONE_SIMULATOR) {          ZBarCameraSimulator *cameraSimulator          = [[ZBarCameraSimulator alloc]initWithViewController:self];          cameraSimulator.readerView = readerView;      }      [self.view addSubview:readerView];        [readerView start];    }    - (void) readerView: (ZBarReaderView*) view       didReadSymbols: (ZBarSymbolSet*) syms            fromImage: (UIImage*) img  {      // do something useful with results      for(ZBarSymbol *sym in syms) {          resultText.text = sym.data;          break;      }      [readerView stop];  }  

 

IOS 使用 ZbarSDK 二維碼掃描

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.