亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

iOS 二維碼生成及掃碼詳解及實例代碼

2020-07-26 03:03:21
字體:
來源:轉載
供稿:網友

iOS二維碼生成及掃碼

     現在越來越多的應用加入二維碼相關的業務,在iOS開發市場上很多開發人員都在使用第三方的掃碼與生成二維碼的控件,個人認為此類的第三方控件識別度不高。最近正好整理新框架的事情,研究了一下。具體代碼如下 

生成二維碼代碼

/**  * @author 半  飽, 15-12-18  *  * @brief 生成二維碼圖片  *  * @param code  生成二維碼圖片內容  * @param width 二維碼圖片寬度  * @param height 二維碼圖片高度  *  * @return 返回UIImage對象  */ - (UIImage *)generateQRCode:(NSString *)code width:(CGFloat)width height:(CGFloat)height {   CIImage *qrcodeImage;   NSData *data = [code dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:false];   CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];      [filter setValue:data forKey:@"inputMessage"];   [filter setValue:@"H" forKey:@"inputCorrectionLevel"];   qrcodeImage = [filter outputImage];      CGFloat scaleX = width / qrcodeImage.extent.size.width;   CGFloat scaleY = height / qrcodeImage.extent.size.height;   CIImage *transformedImage = [qrcodeImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY)];      return [UIImage imageWithCIImage:transformedImage]; } 

 掃描二維碼代碼

#import <AVFoundation/AVFoundation.h>  static const float lightWidth = 240.f; static const float lightHeight = 240.f; static const float crossLineWidth = 2.f; static const float crossLineHeight = 15.f;  @interface BBScanCodeViewController ()<AVCaptureMetadataOutputObjectsDelegate> {   float leftWith;   float topHeight; } @property (strong , nonatomic ) AVCaptureDevice *captureDevice; @property (strong , nonatomic ) AVCaptureDeviceInput *captureInput; @property (strong , nonatomic ) AVCaptureMetadataOutput *captureOutput; @property (strong , nonatomic ) AVCaptureSession *captureSession; @property (strong , nonatomic ) AVCaptureVideoPreviewLayer *capturePreview;  @property (strong,nonatomic) UIButton *flashLightBtn; @property (strong,nonatomic) UIImageView *lineImageView;  @end  @implementation BBScanCodeViewController @synthesize captureDevice = _captureDevice; @synthesize captureInput = _captureInput; @synthesize captureOutput = _captureOutput; @synthesize capturePreview = _capturePreview; @synthesize captureSession = _captureSession; @synthesize delegate = _delegate; @synthesize isRectScan = _isRectScan; @synthesize lineImageView = _lineImageView; @synthesize flashLightBtn = _flashLightBtn; - (void)viewDidLoad {      [super viewDidLoad];   self.isShowNavigationItem = YES;   CGRect screenRect = [UIScreen mainScreen].bounds;   leftWith = (screenRect.size.width - lightWidth) / 2;   topHeight =(screenRect.size.height - lightHeight) / 2;    #if !TARGET_IPHONE_SIMULATOR   [self initScanCode]; #endif   [self initLayer];   [self initViewControl];          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willResignActiveNotification) name:UIApplicationWillResignActiveNotification object:nil]; //監聽是否觸發home鍵掛起程序.   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActiveNotification) name:UIApplicationDidBecomeActiveNotification object:nil]; //監聽是否重新進入程序程序. }  -(void)viewWillDisappear:(BOOL)animated {    [self stopScanCode];   [super viewWillDisappear:animated]; }  - (void)willResignActiveNotification {   _flashLightBtn.selected = NO; } - (void)didBecomeActiveNotification {  } //加載界面上的控件,如:加上閃光燈按鈕等 - (void)initViewControl {    @autoreleasepool {     _flashLightBtn = [UIButton buttonWithType:UIButtonTypeCustom];     [_flashLightBtn setImage:[UIImage imageNamed:@"OpenFlashLight.png"] forState:UIControlStateNormal];     [_flashLightBtn setImage:[UIImage imageNamed:@"CloseFlashLight.png"] forState:UIControlStateSelected];     _flashLightBtn.frame = CGRectMake(leftWith, 80.f, 30.f, 30.f);     [_flashLightBtn addTarget:self action:@selector(systemFlashLight) forControlEvents:UIControlEventTouchUpInside];     [self.view addSubview:_flashLightBtn];          _lineImageView = [[UIImageView alloc] initWithImage:nil];     _lineImageView.backgroundColor = [UIColor greenColor];     _lineImageView.frame = CGRectMake(leftWith, topHeight, lightWidth, 2);     [self.view addSubview:_lineImageView];     [self scanLineAnimation];   }    }  - (void)scanLineAnimation {   [UIView beginAnimations:nil context:nil];   [UIView setAnimationDuration:4.f];   //設置代理   [UIView setAnimationDelegate:self];   //設置動畫執行完畢調用的事件   [UIView setAnimationDidStopSelector:@selector(didViewAnimation)];   _lineImageView.frame = CGRectMake(leftWith,topHeight + lightHeight-2,lightWidth,2);   [UIView commitAnimations];  }  -(void)didViewAnimation { //  self.navigationController   _lineImageView.frame = CGRectMake(leftWith, topHeight, lightWidth, 2);   [self scanLineAnimation]; }  - (void)insertLayerWithFrame:(CGRect)frame withBackgroundColor:(UIColor *)backgroundColor {   @autoreleasepool {     CALayer *layer = [CALayer layer];     layer.backgroundColor = backgroundColor.CGColor;     layer.frame = frame;     [self.view.layer addSublayer:layer];   } } //初始化layer層,繪制半透明區域 -(void) initLayer {   //公共參數   UIColor *fillColor = [UIColor colorWithRed:0xae/255.f green:0xae/255.f blue:0xae/255.f alpha:0.4];   UIColor *crossColor = [UIColor greenColor];   CGRect screenRect = [UIScreen mainScreen].bounds;   [self insertLayerWithFrame:CGRectMake(0, 0, leftWith, screenRect.size.height) withBackgroundColor:fillColor];   [self insertLayerWithFrame:CGRectMake(leftWith, 0, lightWidth, topHeight) withBackgroundColor:fillColor];   [self insertLayerWithFrame:CGRectMake(leftWith + lightWidth, 0, leftWith, screenRect.size.height) withBackgroundColor:fillColor];   [self insertLayerWithFrame:CGRectMake(leftWith, topHeight + lightHeight, lightWidth, topHeight) withBackgroundColor:fillColor];         [self insertLayerWithFrame:CGRectMake(leftWith, topHeight, crossLineWidth, crossLineHeight) withBackgroundColor:crossColor];   [self insertLayerWithFrame:CGRectMake(leftWith, topHeight, crossLineHeight, crossLineWidth) withBackgroundColor:crossColor];      [self insertLayerWithFrame:CGRectMake(leftWith + lightWidth - crossLineHeight, topHeight, crossLineHeight, crossLineWidth) withBackgroundColor:crossColor];   [self insertLayerWithFrame:CGRectMake(leftWith + lightWidth - crossLineWidth, topHeight, crossLineWidth, crossLineHeight) withBackgroundColor:crossColor];      [self insertLayerWithFrame:CGRectMake(leftWith, topHeight + lightHeight - crossLineHeight, crossLineWidth, crossLineHeight) withBackgroundColor:crossColor];   [self insertLayerWithFrame:CGRectMake(leftWith, topHeight + lightHeight - crossLineWidth, crossLineHeight, crossLineWidth) withBackgroundColor:crossColor];      [self insertLayerWithFrame:CGRectMake(leftWith + lightWidth - crossLineHeight, topHeight + lightHeight - crossLineWidth, crossLineHeight, crossLineWidth) withBackgroundColor:crossColor];   [self insertLayerWithFrame:CGRectMake(leftWith + lightWidth - crossLineWidth, topHeight + lightHeight - crossLineHeight, crossLineWidth, crossLineHeight) withBackgroundColor:crossColor]; }  -(void)initScanCode {   @autoreleasepool {     _captureDevice = [ AVCaptureDevice defaultDeviceWithMediaType : AVMediaTypeVideo];     _captureInput = [ AVCaptureDeviceInput deviceInputWithDevice : _captureDevice error : nil ];     _captureOutput = [[ AVCaptureMetadataOutput alloc ] init ];     [_captureOutput setMetadataObjectsDelegate : self queue : dispatch_get_main_queue ()];     if (_isRectScan) {       CGRect screenRect = [UIScreen mainScreen].bounds;       [ _captureOutput setRectOfInterest : CGRectMake (topHeight / screenRect.size.height, leftWith / screenRect.size.width, lightHeight/screenRect.size.height, lightWidth / screenRect.size.width)];     }      _captureSession = [[ AVCaptureSession alloc ] init ];     [_captureSession setSessionPreset : AVCaptureSessionPresetHigh ];     if ([_captureSession canAddInput : _captureInput ])     {       [_captureSession addInput : _captureInput ];     }     if ([_captureSession canAddOutput : _captureOutput ])     {       [_captureSession addOutput : _captureOutput ];     }     _captureOutput.metadataObjectTypes = @[AVMetadataObjectTypeQRCode ] ;          _capturePreview =[ AVCaptureVideoPreviewLayer layerWithSession :_captureSession ];     _capturePreview.videoGravity = AVLayerVideoGravityResizeAspectFill ;     _capturePreview.frame = self.view.layer.bounds ;     [self.view.layer insertSublayer : _capturePreview atIndex : 0 ];     [_captureSession startRunning ];   } }  - ( void )captureOutput:( AVCaptureOutput *)captureOutput didOutputMetadataObjects:( NSArray *)metadataObjects fromConnection:( AVCaptureConnection *)connection {   if (metadataObjects != nil && [metadataObjects count] > 0) {     AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];     NSString *scanCodeResult;     if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {       [self stopScanCode];       scanCodeResult = metadataObj.stringValue;       //回調信息       if (_delegate && [_delegate respondsToSelector:@selector(scanCodeResultByViewController:withScanCodeResult:)]) {         [_delegate scanCodeResultByViewController:self withScanCodeResult:scanCodeResult];         [self.navigationController popViewControllerAnimated:YES];       }     } else {       NSLog(@"掃描信息錯誤!");     }   } }  - (void)systemFlashLight { #if !TARGET_IPHONE_SIMULATOR   if([_captureDevice hasTorch] && [self.captureDevice hasFlash])   {     [_captureSession beginConfiguration];     [_captureDevice lockForConfiguration:nil];     if(_captureDevice.torchMode == AVCaptureTorchModeOff)     {       _flashLightBtn.selected = YES;       [_captureDevice setTorchMode:AVCaptureTorchModeOn];       [_captureDevice setFlashMode:AVCaptureFlashModeOn];     }     else {       _flashLightBtn.selected = NO;       [_captureDevice setTorchMode:AVCaptureTorchModeOff];       [_captureDevice setFlashMode:AVCaptureFlashModeOff];     }     [_captureDevice unlockForConfiguration];     [_captureSession commitConfiguration];   } #else   [CommonUtil showAlert:G_ALERTTITLE withMessage:@"虛擬設備不能運行攝像頭!"]; #endif }  -(void)stopScanCode {   [_captureSession stopRunning];   _captureSession = nil;   _captureDevice = nil;   _captureInput = nil;   _captureOutput = nil;   [_capturePreview removeFromSuperlayer]; }  - (void)didReceiveMemoryWarning {   [super didReceiveMemoryWarning]; }  @end 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲国产天堂网精品网站| 九九视频直播综合网| 国产精品主播视频| 亚洲码在线观看| 国产精品成人国产乱一区| 性色av一区二区三区红粉影视| 亚洲国产精品成人一区二区| 亚洲欧美精品中文字幕在线| 日韩av不卡电影| 亚洲激情视频在线播放| 欧美日韩爱爱视频| 欧美精品激情在线观看| 欧美精品在线免费播放| 亚洲人成伊人成综合网久久久| 欧美激情第1页| 91久久久久久久久久久| 国产亚洲视频中文字幕视频| 久久综合网hezyo| 日韩高清有码在线| 国产精品一区二区久久| 国产欧美精品久久久| 国产噜噜噜噜噜久久久久久久久| 久久综合久久八八| 亚洲高清av在线| 亚洲香蕉在线观看| 欧美午夜片在线免费观看| 亚洲国产精品成人一区二区| 色在人av网站天堂精品| 久久久久久这里只有精品| 日韩中文字幕在线看| 亚洲精品电影网| 高跟丝袜欧美一区| 亚洲激情免费观看| 国产精品老女人精品视频| 国产免费久久av| 韩剧1988免费观看全集| 日本电影亚洲天堂| 日韩精品极品在线观看| 51ⅴ精品国产91久久久久久| 欧美激情性做爰免费视频| 亚洲字幕一区二区| 欧美最猛性xxxxx免费| 91免费欧美精品| 一区二区三区国产在线观看| 亚洲性线免费观看视频成熟| 国产区亚洲区欧美区| 亚洲男人第一av网站| 欧美成人在线网站| 久久久99久久精品女同性| 性欧美亚洲xxxx乳在线观看| 国产精品69av| 欧美日韩国产一中文字不卡| 国产日韩精品在线播放| 日韩欧美视频一区二区三区| 国产欧美日韩中文字幕| 亚洲视频在线观看视频| 一区二区三区精品99久久| 欧美大片免费观看在线观看网站推荐| 亚洲成人黄色在线| 亚洲精品日韩在线| 精品动漫一区二区三区| 中文亚洲视频在线| 亚洲欧美一区二区三区四区| 亚洲女人初尝黑人巨大| 成人免费在线网址| 国产精品入口日韩视频大尺度| 久久国产精品电影| 国产成人久久久精品一区| 国产成+人+综合+亚洲欧洲| 亚洲国产欧美一区二区三区同亚洲| 91成人国产在线观看| 一区二区三区无码高清视频| 午夜精品福利视频| 亚洲成人激情小说| 成人午夜激情免费视频| 国产精品999| 国产在线98福利播放视频| 国产精品中文字幕久久久| 亚洲www永久成人夜色| 亚洲free嫩bbb| 国产69精品久久久久9999| 欧美精品在线播放| 成人午夜激情免费视频| 国产精品啪视频| 亚洲白虎美女被爆操| 日韩视频精品在线| 91亚洲精品在线观看| 欧美成人中文字幕在线| 欧美一级电影在线| 亚洲成人三级在线| 亚洲丁香久久久| 日韩av手机在线看| 亚洲精品福利在线| 亚洲国产精品电影在线观看| 亚洲已满18点击进入在线看片| 亚洲理论片在线观看| 51视频国产精品一区二区| 国产一区香蕉久久| 欧美激情videoshd| 国产有码在线一区二区视频| 91福利视频在线观看| 尤物tv国产一区| 久久免费视频网站| 日韩在线精品一区| 在线日韩日本国产亚洲| 裸体女人亚洲精品一区| 国产精品永久免费| 亚洲成年人在线播放| 日韩国产精品亚洲а∨天堂免| 中文字幕亚洲欧美日韩2019| 午夜精品久久久久久久99热| 成人福利视频在线观看| 成人免费观看49www在线观看| 久久久久久美女| 成人精品久久一区二区三区| 亚洲影院色在线观看免费| 日韩电影网在线| 久久久亚洲精品视频| 欧美精品电影在线| 国产精品成人观看视频国产奇米| 午夜精品www| 久99九色视频在线观看| 91a在线视频| 一区二区三区回区在观看免费视频| 日韩高清电影免费观看完整版| 91亚洲精品久久久| 亚洲人精品午夜在线观看| 日韩视频亚洲视频| 国产欧美精品在线| 欧美精品久久久久久久久久| 亚洲的天堂在线中文字幕| 欧美日韩爱爱视频| 国产亚洲精品久久久| 国产免费一区二区三区香蕉精| 久久精品国产亚洲一区二区| 久久久久久久国产精品视频| 欧美富婆性猛交| 91极品女神在线| 深夜精品寂寞黄网站在线观看| 欧美丝袜一区二区三区| 亚洲天堂免费在线| 最近2019中文字幕一页二页| 欧美日韩久久久久| 欧美激情视频给我| 日韩精品亚洲精品| 成人妇女淫片aaaa视频| 精品激情国产视频| 亚洲精品少妇网址| 午夜精品在线观看| www国产亚洲精品久久网站| 中文字幕精品影院| 亚洲一区二区三区在线视频| 久久人人爽人人爽人人片av高请| 揄拍成人国产精品视频| 国产伦精品免费视频| 国产精品日韩一区| 亚洲视频在线免费看| 国产免费一区二区三区香蕉精| 丝袜美腿亚洲一区二区| 亚洲网站在线看| 久久精品国产亚洲精品2020| 日韩精品极品毛片系列视频| 成人免费淫片aa视频免费| 欧美肥老太性生活视频|