{"id":13696684,"url":"https://github.com/wsl2ls/ScanQRcode","last_synced_at":"2025-05-03T17:32:04.524Z","repository":{"id":56926826,"uuid":"123547578","full_name":"wsl2ls/ScanQRcode","owner":"wsl2ls","description":"功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描工具，支持二维码的扫描、识别图中二维码、生成自定义颜色和中心图标的二维码、监测环境亮度、打开闪光灯这些功能；WSLScanView是参照微信封装的一个扫一扫界面，支持线条颜色、大小、动画图片、矩形扫描框样式的自定义；这个示例本身就是仿照微信的扫一扫功能实现的。","archived":false,"fork":false,"pushed_at":"2019-11-18T02:11:41.000Z","size":8487,"stargazers_count":102,"open_issues_count":4,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T04:35:13.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wsl2ls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-02T07:46:46.000Z","updated_at":"2024-10-19T13:44:54.000Z","dependencies_parsed_at":"2022-08-21T04:20:50.014Z","dependency_job_id":null,"html_url":"https://github.com/wsl2ls/ScanQRcode","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsl2ls%2FScanQRcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsl2ls%2FScanQRcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsl2ls%2FScanQRcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsl2ls%2FScanQRcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wsl2ls","download_url":"https://codeload.github.com/wsl2ls/ScanQRcode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224369696,"owners_count":17299942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:44.894Z","updated_at":"2024-11-13T00:30:52.931Z","avatar_url":"https://github.com/wsl2ls.png","language":"Objective-C","funding_links":[],"categories":["UI Components"],"sub_categories":[],"readme":"# WSLNativeScanTool\n\n简书地址：https://www.jianshu.com/u/e15d1f644bea\n\n![](https://img.shields.io/badge/license-MIT%20-green.svg)\n![](https://img.shields.io/badge/pod-v1.0-brightgreen.svg)\n![](https://img.shields.io/badge/platform-iOS-orange.svg)\n![](https://img.shields.io/badge/support-iOS9.0-green.svg)\n![](https://img.shields.io/badge/build-passing-green.svg)\n\n\n![效果预览1.gif](http://upload-images.jianshu.io/upload_images/1708447-6f8d911290ccafb4.gif?imageMogr2/auto-orient/strip) ![效果预览2.gif](http://upload-images.jianshu.io/upload_images/1708447-70b61f5542fc07a1.gif?imageMogr2/auto-orient/strip)\n\n\u003e功能描述:[WSLNativeScanTool](https://github.com/wslcmk/ScanQRcode.git)是在利用原生API的条件下封装的二维码扫描工具，支持二维码的扫描、识别图中二维码、生成自定义颜色和中心图标的二维码、监测环境亮度、打开闪光灯这些功能；[WSLScanView](https://github.com/wslcmk/ScanQRcode.git)是参照微信封装的一个扫一扫界面，支持线条颜色、大小、动画图片、矩形扫描框样式的自定义；这个示例本身就是仿照微信的扫一扫功能实现的。\n\n* 详细实现就不在此唠叨了，直接去看代码吧，注释详细是我的习惯😀→[WSLNativeScanTool](https://github.com/wslcmk/ScanQRcode.git)\n* 来看一下WSLNativeScanTool.h ，用法很明朗\n```\n@import UIKit;\n@import AVFoundation;\n\n#import \u003cFoundation/Foundation.h\u003e\n\n/**\n 扫描完成的回调\n @param scanString 扫描出的字符串\n */\ntypedef void(^WSLScanFinishedBlock)( NSString * _Nullable scanString);\n\n/**\n 监听环境光感的回调\n @param brightness 亮度值\n */\ntypedef void(^WSLMonitorLightBlock)( float brightness);\n\n@interface WSLNativeScanTool : NSObject\n\n/**\n 扫描出结果后的回调 ，注意循环引用的问题\n */\n@property (nonatomic, copy) WSLScanFinishedBlock _Nullable scanFinishedBlock;\n\n/**\n 监听环境光感的回调,如果 != nil 表示开启监测环境亮度功能\n */\n@property (nonatomic, copy) WSLMonitorLightBlock _Nullable monitorLightBlock;\n\n/**\n 闪光灯的状态,不需要设置，仅供外边判断状态使用\n */\n@property (nonatomic, assign) BOOL flashOpen;\n\n/**\n 初始化 扫描工具\n @param preview 展示输出流的视图\n @param scanFrame 扫描中心识别区域范围\n */\n- (instancetype )initWithPreview:(UIView *)preview andScanFrame:(CGRect)scanFrame;\n\n/**\n 闪光灯开关\n */\n- (void)openFlashSwitch:(BOOL)open;\n\n- (void)sessionStartRunning;\n\n- (void)sessionStopRunning;\n\n/**\n 识别图中二维码\n */\n- (void)scanImageQRCode:(UIImage *_Nullable)imageCode;\n\n/**\n 生成自定义样式二维码\n 注意：有些颜色结合生成的二维码识别不了\n @param codeString 字符串\n @param size 大小\n @param backColor 背景色\n @param frontColor 前景色\n @param centerImage 中心图片\n @return image二维码\n */\n+ (UIImage *)createQRCodeImageWithString:(nonnull NSString *)codeString andSize:(CGSize)size andBackColor:(nullable UIColor *)backColor andFrontColor:(nullable UIColor *)frontColor andCenterImage:(nullable UIImage *)centerImage;\n\n```\n* 再来看一下WSLScanView.h,用法也明朗😁\n\n```\n//\n//  WSLScanView.h\n//  ScanQRcode\n//\n//  Created by 王双龙 on 2018/2/28.\n//  Copyright © 2018年 https://www.jianshu.com/u/e15d1f644bea\nAll rights reserved.\n//\n\n#import \u003cUIKit/UIKit.h\u003e\n\ntypedef void(^WSLMyQRCodeBlock)(void);\n\ntypedef void(^WSLFlashSwitchBlock)(BOOL open);\n\n@interface WSLScanView : UIView\n\n/**\n 点击我的二维码的回调\n */\n@property (nonatomic,copy) WSLMyQRCodeBlock myQRCodeBlock;\n\n/**\n 打开/关闭闪光灯的回调\n */\n@property (nonatomic,copy) WSLFlashSwitchBlock flashSwitchBlock;\n\n#pragma mark - 扫码区域\n\n/**\n 扫码区域 默认为正方形,x = 60, y = 100\n */\n@property (nonatomic,assign)CGRect scanRetangleRect;\n/**\n @brief  是否需要绘制扫码矩形框，默认YES\n */\n@property (nonatomic, assign) BOOL isNeedShowRetangle;\n/**\n @brief  矩形框线条颜色\n */\n@property (nonatomic, strong, nullable) UIColor *colorRetangleLine;\n\n#pragma mark - 矩形框(扫码区域)周围4个角\n\n//4个角的颜色\n@property (nonatomic, strong, nullable) UIColor* colorAngle;\n//扫码区域4个角的宽度和高度 默认都为20\n@property (nonatomic, assign) CGFloat photoframeAngleW;\n@property (nonatomic, assign) CGFloat photoframeAngleH;\n/**\n @brief  扫码区域4个角的线条宽度,默认6\n */\n@property (nonatomic, assign) CGFloat photoframeLineW;\n\n#pragma mark --动画效果\n\n/**\n *  动画效果的图像\n */\n@property (nonatomic,strong, nullable) UIImage * animationImage;\n/**\n 非识别区域颜色,默认 RGBA (0,0,0,0.5)\n */\n@property (nonatomic, strong, nullable) UIColor * notRecoginitonArea;\n\n/**\n *  开始扫描动画\n */\n- (void)startScanAnimation;\n/**\n *  结束扫描动画\n */\n- (void)stopScanAnimation;\n\n/**\n 正在处理扫描到的结果\n */\n- (void)handlingResultsOfScan;\n\n/**\n 完成扫描结果处理\n */\n- (void)finishedHandle;\n\n/**\n 是否显示闪光灯开关\n @param show YES or NO\n */\n- (void)showFlashSwitch:(BOOL)show;\n@end\n\n```\n\n*  初始化WSLNativeScanTool和WSLScanView\n\n```\n//输出流视图\n    UIView *preview  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 0)];\n    [self.view addSubview:preview];\n    \n    __weak typeof(self) weakSelf = self;\n    \n    //构建扫描样式视图\n    _scanView = [[WSLScanView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 0)];\n    _scanView.scanRetangleRect = CGRectMake(60, 120, (self.view.frame.size.width - 2 * 60),  (self.view.frame.size.width - 2 * 60));\n    _scanView.colorAngle = [UIColor greenColor];\n    _scanView.photoframeAngleW = 20;\n    _scanView.photoframeAngleH = 20;\n    _scanView.photoframeLineW = 2;\n    _scanView.isNeedShowRetangle = YES;\n    _scanView.colorRetangleLine = [UIColor whiteColor];\n    _scanView.notRecoginitonArea = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];\n    _scanView.animationImage = [UIImage imageNamed:@\"scanLine\"];\n    _scanView.myQRCodeBlock = ^{\n     [WSLNativeScanTool createQRCodeImageWithString:@\"https://www.jianshu.com/u/e15d1f644bea\" andSize:CGSizeMake(250, 250) andBackColor:[UIColor whiteColor] andFrontColor:[UIColor orangeColor] andCenterImage:[UIImage imageNamed:@\"piao\"]];\n        createQRCodeController.qrString = @\"https://www.jianshu.com/u/e15d1f644bea\";\n    };\n    _scanView.flashSwitchBlock = ^(BOOL open) {\n        [weakSelf.scanTool openFlashSwitch:open];\n    };\n    [self.view addSubview:_scanView];\n    \n    //初始化扫描工具\n    _scanTool = [[WSLNativeScanTool alloc] initWithPreview:preview andScanFrame:_scanView.scanRetangleRect];\n    _scanTool.scanFinishedBlock = ^(NSString *scanString) {\n        NSLog(@\"扫描结果 %@\",scanString);\n        [weakSelf.scanTool sessionStopRunning];\n        [weakSelf.scanTool openFlashSwitch:NO];\n    };\n    _scanTool.monitorLightBlock = ^(float brightness) {\n        NSLog(@\"环境光感 ： %f\",brightness);\n        if (brightness \u003c 0) {\n            // 环境太暗，显示闪光灯开关按钮\n            [weakSelf.scanView showFlashSwitch:YES];\n        }else if(brightness \u003e 0){\n            // 环境亮度可以,且闪光灯处于关闭状态时，隐藏闪光灯开关\n            if(!weakSelf.scanTool.flashOpen){\n                [weakSelf.scanView showFlashSwitch:NO];\n            }\n        }\n    };\n    [_scanTool sessionStartRunning];\n    [_scanView startScanAnimation];\n    \n```\n\n![赞.gif](http://upload-images.jianshu.io/upload_images/1708447-ce06388c244874ce.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n## Welcome To Follow Me\n\n\u003e  您的follow和start，是我前进的动力，Thanks♪(･ω･)ﾉ\n\u003e * [简书](https://www.jianshu.com/u/e15d1f644bea)\n\u003e * [微博](https://weibo.com/5732733120/profile?rightmod=1\u0026wvr=6\u0026mod=personinfo\u0026is_all=1)\n\u003e * [掘金](https://juejin.im/user/5c00d97b6fb9a049fb436288)\n\u003e * [CSDN](https://blog.csdn.net/wsl2ls)\n\u003e * QQ交流群：835303405\n\n\u003e 欢迎扫描下方二维码关注——iOS开发进阶之路——微信公众号：iOS2679114653 本公众号是一个iOS开发者们的分享，交流，学习平台，会不定时的发送技术干货，源码,也欢迎大家积极踊跃投稿，(择优上头条) ^_^分享自己开发攻城的过程，心得，相互学习，共同进步，成为攻城狮中的翘楚！\n\n![iOS开发进阶之路.jpg](http://upload-images.jianshu.io/upload_images/1708447-c2471528cadd7c86.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsl2ls%2FScanQRcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwsl2ls%2FScanQRcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsl2ls%2FScanQRcode/lists"}