http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8351|回复: 13

[IPHONE] use Zbar SDK sample

[复制链接]
发表于 2013-7-18 16:34:10 | 显示全部楼层 |阅读模式
最近在忙那项目,没有太多时间的。时间关系。今天贴一下那简单的代码。后续再发帖关于[IOS左右滑动菜单]、[自定义横向UIPickerView]、[kal Clendar日历的使用]等其他新帖。希望可以帮助到需要的人。

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


2、加入Library如下:


i

i


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

Screen Shot 2013-07-18 at 4.29.46 PM.png

4、新建你的viewController,.h文件如下(未使用xib):
  1. #import <UIKit/UIKit.h>
  2. #import "ZBarSDK.h"

  3. @interface QRCodeViewController : UIViewController<ZBarReaderViewDelegate> {

  4.     ZBarReaderView *readerView;
  5.     ZBarCameraSimulator *cameraSim;
  6.    
  7. }

  8. @end
复制代码
5、.m文件如下:
  1. #import "QRCodeViewController.h"

  2. @interface QRCodeViewController ()

  3. @end

  4. @implementation QRCodeViewController

  5. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  6. {
  7.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  8.     if (self) {
  9.         [self setTitle:@"QRCode"];
  10.         [self.tabBarItem setTitle:@"QRCode"];
  11.     }
  12.     return self;
  13. }

  14. - (void)viewDidLoad
  15. {
  16.     [super viewDidLoad];
  17.   
  18.     readerView = [[ZBarReaderView alloc] init];
  19.     readerView.readerDelegate = self;
  20.     [readerView setShowsFPS:YES];
  21.     [readerView setAllowsPinchZoom:YES];
  22.     [readerView setFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height - 20)];
  23.    
  24.     [self.view addSubview:readerView];
  25.    
  26.    //你可以自定義這個掃瞄界面在這裡隨意定義。
  27.    
  28.    
  29.     if(TARGET_IPHONE_SIMULATOR) {
  30.         cameraSim = [[ZBarCameraSimulator alloc]
  31.                      initWithViewController: self];
  32.         cameraSim.readerView = readerView;
  33.     }
  34. }

  35. - (void)viewWillAppear:(BOOL)animated
  36. {
  37.     [super viewWillAppear:animated];
  38. }

  39. - (void)viewDidAppear:(BOOL)animated
  40. {
  41.     [readerView start];
  42. }

  43. - (void)didReceiveMemoryWarning
  44. {
  45.     [super didReceiveMemoryWarning];
  46.     // Dispose of any resources that can be recreated.
  47. }

  48. - (void)viewDidDisappear:(BOOL)animated
  49. {
  50.     [super viewDidDisappear:YES];
  51.     [readerView stop];
  52. }

  53. - (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
  54. {
  55.     for (ZBarSymbol *sym in symbols) {
  56.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"掃瞄結果" message:[sym data] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  57.         [alert show];
  58.         break;
  59.     }
  60. }

  61. -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  62. {
  63.     // 得到条形码结果
  64. //    id<NSFastEnumeration> results =
  65. //    [info objectForKey: ZBarReaderControllerResults];
  66. //    ZBarSymbol *symbol = nil;
  67. //    for(symbol in results)
  68. //        break;
  69.     //获得到条形码
  70.     //NSString *dataNum=symbol.data;
  71.     //扫描界面退出
  72.     [picker dismissModalViewControllerAnimated: YES];
  73. }

  74. @end
复制代码
6、那demo截圖如下:
Screen Shot 2013-07-18 at 4.33.03 PM.png

希望對你理解有些幫助。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-7-18 16:53:02 | 显示全部楼层
强烈支持楼主ing……
发表于 2013-7-18 17:15:22 | 显示全部楼层
真是难得给力的帖子啊,强烈支持楼主。
发表于 2013-7-18 17:15:43 | 显示全部楼层
谢谢大神
回复

使用道具 举报

发表于 2013-7-18 17:16:04 | 显示全部楼层
顶起
回复

使用道具 举报

发表于 2013-7-18 17:16:22 | 显示全部楼层
顶起,非常不错,学习学习。。。
发表于 2013-7-18 17:16:47 | 显示全部楼层
受教了,学习中……
 楼主| 发表于 2013-7-19 09:19:17 | 显示全部楼层
WYwinstonWY 发表于 2013-7-18 17:16
顶起,非常不错,学习学习。。。

謝謝。共同學習交流。
发表于 2013-8-5 16:15:31 | 显示全部楼层
很好。解决我一道大难题啊。
发表于 2013-8-5 16:35:56 | 显示全部楼层
写的很好啊。。感谢大神
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-27 16:20

© 2014-2021

快速回复 返回顶部 返回列表