HHBarCodeViewController 是一个使用 iOS 7 原生条形码扫描 API 的快速模态条形码阅读器。
最初是为了我自己使用,因为找到的唯一实现只有 博客文章 中的代码片段,所以我将这段代码合并在一起,制作成一个易于展示且具有花哨代理回调的模态视图控制器。
好耶。
通过 CocoaPods 安装最简单。只需将以下行添加到您的 Podfile: pod 'HHBarCodeViewController'
使用方法很简单。只需使用 [HHBarCodeViewController new]
实例化 HHBarCodeViewController 并展示或推送它。当识别到条形码时,代理方法 barCodeViewController:didDetectBarCode:
或块 detectedBarCodeBlock()
将被调用。
如果您使用返回的条形码,强烈建议您在关闭 ViewController 后在完成中进行操作。这将防止重复动作,因为 HHBarCodeViewController
在其生命周期中多次调用该代理方法。
如下所示
- (void) barCodeViewController:(UIViewController *)barCodeViewController didDetectBarCode:(NSString *)barCode {
[self dismissViewControllerAnimated:YES completion:^{
dataTextView.text = barCode;
}];
}
Harlan Haskins (@harlanhaskins)
HHBarCodeViewController 可在 MIT 许可证下使用,此副本在名为 LICENSE
的文件中。