DOC

use Zbar SDK sample

By Annie Greene,2014-09-09 14:54
12 views 0
use Zbar SDK sample

    use Zbar SDK sample

    1、参考前面Zbar SDK iOS使用ZbarSDK实现扫描二维码以及条形码功能 的帖子将那下载SDK拖入到项目中。

2、加入Library如下!

3、到Build Settings刪除那 armv7s,留下armv7,如下!

4、新建你的viewController.h文件如下?未使用xib?!

    1. #import <UIKit/UIKit.h>

    2. #import "ZBarSDK.h"

    3.

    4. @interface QRCodeViewController :

    UIViewController<ZBarReaderViewDelegate> {

    5.

    6. ZBarReaderView *readerView;

    7. ZBarCameraSimulator *cameraSim;

8.

    9. }

    10.

    11. @end

    12.

    复制代码

    5.m文件如下!

    普通浏览复制代码保存代码打印代码

    1. #import "QRCodeViewController.h" 2.

    3. @interface QRCodeViewController () 4.

    5. @end

    6.

    7. @implementation QRCodeViewController 8.

    9.

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

    bBundleOrNil

    10. {

    11. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNi

    l];

    12. if (self) {

    13. [self setTitle:@"QRCode"]; 14. [self.tabBarItem setTitle:@"QRCode"]; 15. }

    16. return self;

    17. }

    18.

    19. - (void)viewDidLoad

    20. {

    21. [super viewDidLoad];

    22.

    23. readerView = [[ZBarReaderView alloc] init];

    24. readerView.readerDelegate = self; 25. [readerView setShowsFPS:YES]; 26. [readerView setAllowsPinchZoom:YES]; 27. [readerView setFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen

    ].bounds.size.height - 20)];

    28.

    29. [self.view addSubview:readerView]; 30.

31. //你可以自定義這個掃瞄界面在這裡隨意定義。

    32.

    33.

    34. if(TARGET_IPHONE_SIMULATOR) { 35. cameraSim = [[ZBarCameraSimulator alloc] 36. initWithViewController: self]; 37. cameraSim.readerView = readerView; 38. }

    39. }

    40.

    41. - (void)viewWillAppear:(BOOL)animated 42. {

    43. [super viewWillAppear:animated]; 44. }

    45.

    46. - (void)viewDidAppear:(BOOL)animated 47. {

    48. [readerView start];

    49. }

    50.

    51. - (void)didReceiveMemoryWarning

    52. {

    53. [super didReceiveMemoryWarning]; 54. // Dispose of any resources that can be recreated.

    55. }

    56.

    57. - (void)viewDidDisappear:(BOOL)animated 58. {

    59. [super viewDidDisappear:YES]; 60. [readerView stop];

    61. }

    62.

    63.

    - (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBar

    SymbolSet *)symbols fromImage:(UIImage *)image 64. {

    65. for (ZBarSymbol *sym in symbols) { 66. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"

    掃瞄結果

    " message:[sym data] delegate:self cancelButtonTitle:@"OK" otherButt

    onTitles:nil, nil];

    67. [alert show];

    68. break;

    69. }

70. }

    71.

    72.

    -(void) imagePickerController:(UIImagePickerController *)picker didF

    inishPickingMediaWithInfo:(NSDictionary *)info 73. {

    74. // 得到条形码结果

    75. // id<NSFastEnumeration> results = 76. // [info objectForKey: ZBarReaderControllerResults];

    77. // ZBarSymbol *symbol = nil;

    78. // for(symbol in results)

    79. // break;

    80. //获得到条形码

    81. //NSString *dataNum=symbol.data; 82. //扫描界面退出

    83. [picker dismissModalViewControllerAnimated: YES]; 84. }

    85.

    86. @end

    87.

    6、那demo截圖如下!

Report this document

For any questions or suggestions please email
cust-service@docsford.com