ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:190.50KB ,
资源ID:30266979      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/30266979.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(iOS 扫一扫功能实现.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

iOS 扫一扫功能实现.docx

1、iOS 扫一扫功能实现iOS 扫一扫功能实现下面贴上代码:AppDelegate.m:objc view plain copy 在CODE上查看代码片派生到我的代码片- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions self.window = UIWindow alloc initWithFrame:UIScreen mainScreen bounds; self.window.rootViewController = UINa

2、vigationController alloc initWithRootViewController:ViewController alloc init; self.window.backgroundColor = UIColor whiteColor; self.window makeKeyAndVisible; return YES; ViewController:objc view plain copy 在CODE上查看代码片派生到我的代码片#import interface ViewController : UIViewController end /* -分割线- */ #impo

3、rt ViewController.h #import HWScanViewController.h implementation ViewController - (void)viewDidLoad super viewDidLoad; self.view.backgroundColor = UIColor whiteColor; /创建控件 self creatControl; - (void)creatControl /扫一扫按钮 UIButton *scanBtn = UIButton alloc initWithFrame:CGRectMake(100, 100, 100, 44);

4、 scanBtn.backgroundColor = UIColor orangeColor; scanBtn setTitle:扫一扫 forState:UIControlStateNormal; scanBtn addTarget:self action:selector(scanBtnOnClick) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:scanBtn; - (void)scanBtnOnClick HWScanViewController *vc = HWScanViewControlle

5、r alloc init; self.navigationController pushViewController:vc animated:YES; end HWScanViewController:objc view plain copy 在CODE上查看代码片派生到我的代码片#import interface HWScanViewController : UIViewController end /* -分割线- */ #import HWScanViewController.h #import #define KMainW UIScreen mainScreen.bounds.size

6、.width #define KMainH UIScreen mainScreen.bounds.size.height interface HWScanViewController () property (nonatomic, strong) NSTimer *timer; property (nonatomic, strong) AVCaptureDevice *device; property (nonatomic, strong) AVCaptureSession *session; property (nonatomic, strong) AVCaptureVideoPreview

7、Layer *preview; property (nonatomic, weak) UIImageView *line; property (nonatomic, assign) NSInteger distance; end implementation HWScanViewController - (void)viewDidLoad super viewDidLoad; /初始化信息 self initInfo; /创建控件 self creatControl; /设置参数 self setupCamera; /添加定时器 self addTimer; - (void)viewWillD

8、isappear:(BOOL)animated super viewWillDisappear:animated; self stopScanning; - (void)initInfo /背景色 self.view.backgroundColor = UIColor blackColor; /导航标题 self.navigationItem.title = 二维码/条形码; /导航右侧相册按钮 self.navigationItem.rightBarButtonItem = UIBarButtonItem alloc initWithTitle:相册 style:UIBarButtonIte

9、mStylePlain target:self action:selector(photoBtnOnClick); - (void)creatControl CGFloat scanW = KMainW * 0.65; CGFloat padding = 10.0f; CGFloat labelH = 20.0f; CGFloat tabBarH = 64.0f; CGFloat cornerW = 26.0f; CGFloat marginX = (KMainW - scanW) * 0.5; CGFloat marginY = (KMainH - scanW - padding - lab

10、elH) * 0.5; /遮盖视图 for (int i = 0; i 4; i+) UIView *cover = UIView alloc initWithFrame:CGRectMake(0, (marginY + scanW) * i, KMainW, marginY + (padding + labelH) * i); if (i = 2 | i = 3) cover.frame = CGRectMake(marginX + scanW) * (i - 2), marginY, marginX, scanW); cover.backgroundColor = UIColor blac

11、kColor colorWithAlphaComponent:0.5f; self.view addSubview:cover; /扫描视图 UIView *scanView = UIView alloc initWithFrame:CGRectMake(marginX, marginY, scanW, scanW); self.view addSubview:scanView; /扫描线 UIImageView *line = UIImageView alloc initWithFrame:CGRectMake(0, 0, scanW, 2); self drawLineForImageVi

12、ew:line; scanView addSubview:line; self.line = line; /边框 UIView *borderView = UIView alloc initWithFrame:CGRectMake(0, 0, scanW, scanW); borderView.layer.borderColor = UIColor whiteColor CGColor; borderView.layer.borderWidth = 1.0f; scanView addSubview:borderView; /扫描视图四个角 for (int i = 0; i KMainW *

13、 0.65) _distance = 0; _line.frame = CGRectMake(0, _distance, KMainW * 0.65, 2); - (void)removeTimer _timer invalidate; _timer = nil; /照明按钮点击事件 - (void)lightBtnOnClick:(UIButton *)btn /判断是否有闪光灯 if (!_device hasTorch) self showAlertWithTitle:当前设备没有闪光灯,无法开启照明功能 message:nil sureHandler:nil cancelHandler

14、:nil; return; btn.selected = !btn.selected; _device lockForConfiguration:nil; if (btn.selected) _device setTorchMode:AVCaptureTorchModeOn; else _device setTorchMode:AVCaptureTorchModeOff; _device unlockForConfiguration; /进入相册 - (void)photoBtnOnClick if (UIImagePickerController isSourceTypeAvailable:

15、UIImagePickerControllerSourceTypePhotoLibrary) UIImagePickerController *controller = UIImagePickerController alloc init; controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; controller.delegate = lf; self presentViewController:controller animated:YES completion:nil; else self showA

16、lertWithTitle:当前设备不支持访问相册 message:nil sureHandler:nil cancelHandler:nil; #pragma mark - AVCaptureMetadataOutputObjectsDelegate - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection /扫描完成 if (metadat

17、aObjects count 0) /停止扫描 self stopScanning; /显示结果 self showAlertWithTitle:扫描结果 message:metadataObjects firstObject stringValue sureHandler:nil cancelHandler:nil; - (void)stopScanning _session stopRunning; _session = nil; _preview removeFromSuperlayer; self removeTimer; #pragma mark - UIImagePickerCon

18、trollrDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info picker dismissViewControllerAnimated:YES completion: /获取相册图片 UIImage *image = infoUIImagePickerControllerOriginalImage; /识别图片 CIDetector *detector = CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:CIDetectorAccuracy:CIDetectorAccuracyHigh; NSArray *features = detector featuresInImage:CIImage imageWithCGImage:image.CGImage; /识别结果 if (features.cou

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1