NSRunLoop类声明的编程接口用于管理输入源对象。一个NSRunLoop对象处理像来自窗体系统中的鼠标和键盘事件,NSPORT对象和NSConnection连接对象这类的输入源。一个NSRunLoop对象也处理的NSTimer事件。

你的应用程序不能建立或明白管理NSRunLoop对象。

每一个NSThread对象。包含应用程序的主线程。具有依据须要自己主动创建一个NSRunLoop对象。假设你须要訪问当前线程的执行循环,能够使用类方法currentRunLoop。

1.下载ZBar的第三方库。加入入project

2.加入相关库
   AVFoundation.framework
   CoreMedia.framework
   CoreVideo.framework
   libiconv.2.4.0.dylib  
3.添加一个以ZBarReaderViewController为父类的控制器。并实现ZBarReaderDelegate代理
4.在控制器中加入例如以下代码
条形码的扫描

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置代理
    self.readerDelegate = self;
    //扫瞄图像
    ZBarImageScanner *mScanner = self.scanner;
    //是否显示绿色的追踪框。注意。即当选择yes的时候。这个框只当扫瞄EAN和I2/5的时候才可见。

    self.tracksSymbols = YES;
    //是否使用备用控制组
    self.showsZBarControls = YES;
    //支持的方向。用ZBarOrientationMask() 和 ZBarOrientationMaskAll
    self.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationMaskPortrait);
    
    //提供自己定义覆盖层。注意,在showsZBarControls启用的情况下才干够用
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    view.backgroundColor = [UIColor grayColor];
    self.cameraOverlayView = view;
    
    //裁剪扫描的图像,在扫描前图像将被裁剪到这个矩形内。这个矩形框是将图像的尺寸和宽高比标准化,
    //有效值将放置矩形内介于0和1的每一个轴。当中x轴相应于图像的长轴。默觉得完整的图像(0。0,1,1)。

//    self.scanCrop
    //调节以适应预览图片
//    self.cameraViewTransform

     //解码配置
    [mScanner setSymbology:ZBAR_I25
                   config:ZBAR_CFG_ENABLE
                       to:0];
// Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.readerView start];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.readerView stop];
}

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //获取扫瞄结果
    id<NSFastEnumeration>
results = [info objectForKey:ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;

     //不过抓住第一个条形码
    for (symbol in results)
        break;
    NSString *text = symbol.data;
        //解决中文乱码问题
    if ([text canBeConvertedToEncoding:NSShiftJISStringEncoding])
{
        text = [NSString stringWithCString:[text cStringUsingEncoding:NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
    }
    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",text],@"resultLabel",[info objectForKey:UIImagePickerControllerOriginalImage],@"resultImgView", nil];
    [self performSelectorOnMainThread:@selector(mainAction:) withObject:dic waitUntilDone:NO];
}

- (void)mainAction:(NSDictionary *)dic
{
    OtherViewController *other = [[OtherViewController alloc] init];
    other.resultString = [dic objectForKey:@"resultLabel"];
    other.image = [dic objectForKey:@"resultImgView"];
    [self.navigationController pushViewController:other animated:YES];

}
此时,我们再来看看ZBarReaderViewController中的ZBarReaderView这个类

// supply a pre-configured image scanner.

//支持一个预先准备的图片扫描
- (id) initWithImageScanner: (ZBarImageScanner*)
imageScanner;

// start the video stream and barcode reader.

//開始视频流和条形码扫描
- (void) start;

// stop the video stream and barcode reader.

//停止视频流和条形码扫描
- (void) stop;

// clear the internal result cache

//清理内部的缓存
- (void) flushCache;

// compensate for device/camera/interface orientation

// 适应设备的方向
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation)
orient

                                 duration: (NSTimeInterval) duration;

// delegate is notified of decode results.

//代理
@property (nonatomic, assign) id<ZBarReaderViewDelegate>
readerDelegate;

// access to image scanner for configuration.

//直接对图片扫描配置
@property (nonatomic, readonly) ZBarImageScanner *scanner;

// whether to display the tracking annotation for uncertain barcodes
// (default YES).

// 是否为不确定的条形码显示追踪
@property (nonatomic) BOOL tracksSymbols;

// color of the tracking box (default green)

//追踪框的颜色,默觉得绿色

@property (nonatomic, retain) UIColor *trackingColor;

// enable pinch gesture recognition for zooming the preview/decode
// (default YES).

// 能否对预览图进行手势缩放,默认是能够的
@property (nonatomic) BOOL allowsPinchZoom;

// torch mode to set automatically (default Auto).

// 0为不闪光。1为闪光

@property (nonatomic) NSInteger torchMode;

// zoom scale factor applied to video preview *and* scanCrop.
// also updated by pinch-zoom gesture.  clipped to range [1,maxZoom],
// defaults to 1.25

// 施加于摄像前景画面和扫描区域的缩放
@property (nonatomic) CGFloat zoom;
- (void) setZoom: (CGFloat) zoom

        animated: (BOOL) animated;

// the region of the image that will be scanned.  normalized coordinates.

// 图片将被扫描的区域,标准坐标

@property (nonatomic) CGRect scanCrop;
二维码的扫描
实现代理ZBarReaderViewDelegate

- (void)readerView:(ZBarReaderView *)readerView
didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
    ZBarSymbol *symbol = nil;
    for (symbol in symbols)
        break;
    NSString *text = symbol.data;
    NSLog(@"%@",text);

}

最新文章

  1. Bootstrap 栅格系统(转载)
  2. Using SYSTEM.MOUSE_ITEM In Oracle Forms
  3. Gramar
  4. hadoop源代码解读
  5. couchDB入门
  6. Java对象序列化的使用和定制
  7. IntentService学习
  8. C#学习笔记-迭代器模式
  9. es6学习笔记--解构赋值
  10. js中的拷贝问题
  11. keras系列︱Sequential与Model模型、keras基本结构功能(一)
  12. 0 vs null
  13. nginx 出现504 Gateway Time-out的解决方法
  14. 使用Visual Studio Team Services敏捷规划和项目组合管理(三)——使用Kanban板
  15. UVA 277 Puzzle
  16. 坑人的 Javascript 模块化编程 require.js
  17. 对于装office 365时,visio不兼容的解决
  18. ELK初探
  19. Python模块:time模块详解(转)
  20. OpenMPI源码剖析:网络通信原理(一)

热门文章

  1. HDU1595-最短路-删边
  2. nyoj164——卡特兰数(待填坑)
  3. Linux 挂载系统盘
  4. FreeMarker初探--介绍
  5. 内存保护机制及绕过方法——通过覆盖部分地址绕过ASLR
  6. is7.0中发布mvc网站,一直无法正常执行路由的解决办法
  7. volatile关键字解析(一)
  8. c++多线程编程:实现标准库accumulate函数的并行计算版本
  9. vue中使用jquery插件
  10. Android程序员学WEB前端(5)-HTML(5)-框架集-Sublime