二维码功能方便快捷,深受用户喜好,本文为你们简单介绍,一对一直播系统开发想要实如今APP内实现扫描二维码功能,须要如下几步。微信
1、首先是二维码的获取和分析,须要一对一直播系统开发源码获取手机摄像头使用权限,设置扫描范围,进入二维码界面后,会对界面进行初始化。session
2、添加一对一直播系统开发源码扫描涂层,设置扫描蒙版,检测边框、镂空、二维码图标的四个角角落。app
//懵层ide
(UIView )hudView
{
if (!_hudView) {
_hudView = [[UIView alloc] initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight)];
CGFloat x = (self.view.frame.size.width - 220)0.5;
CGFloat y = (self.view.frame.size.height - 220)0.4;
CGFloat height = 220;
//镂空
CGRect qrRect = CGRectMake(x,y,height, height);
UIBezierPath path = [UIBezierPath bezierPathWithRoundedRect:self.view.frame cornerRadius:0];
UIBezierPath circlePath = [UIBezierPath bezierPathWithRect:qrRect];
[path appendPath:circlePath];
[path setUsesEvenOddFillRule:YES];
CAShapeLayer fillLayer = [CAShapeLayer layer];
fillLayer.path = path.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4].CGColor;
fillLayer.opacity = 0.5;
[_hudView.layer addSublayer:fillLayer];ui
//白色矩形 UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, height, height)]; CAShapeLayer *shapLayer = [CAShapeLayer layer]; shapLayer.backgroundColor = UIColor.clearColor.CGColor; shapLayer.path = bezierPath.CGPath; shapLayer.lineWidth = 0.5; shapLayer.strokeColor = UIColor.whiteColor.CGColor; shapLayer.fillColor = UIColor.clearColor.CGColor; [_hudView.layer addSublayer:shapLayer]; //红色四个角落 UIBezierPath *cornerBezierPath = [UIBezierPath bezierPath]; [cornerBezierPath moveToPoint:CGPointMake(x, y+30)];//左上角 [cornerBezierPath addLineToPoint:CGPointMake(x, y)]; [cornerBezierPath addLineToPoint:CGPointMake(x+30, y)]; [cornerBezierPath moveToPoint:CGPointMake(x+height-30, y)];//右上角 [cornerBezierPath addLineToPoint:CGPointMake(x+height, y)]; [cornerBezierPath addLineToPoint:CGPointMake(x+height, y+30)]; [cornerBezierPath moveToPoint:CGPointMake(x+height, y+height-30)];//左上角 [cornerBezierPath addLineToPoint:CGPointMake(x+height, y+height)]; [cornerBezierPath addLineToPoint:CGPointMake(x+height-30, y+height)]; [cornerBezierPath moveToPoint:CGPointMake(x+30, y+height)];//左上角 [cornerBezierPath addLineToPoint:CGPointMake(x, y+height)]; [cornerBezierPath addLineToPoint:CGPointMake(x, y+height-30)]; CAShapeLayer *cornerShapLayer = [CAShapeLayer layer]; cornerShapLayer.backgroundColor = UIColor.clearColor.CGColor; cornerShapLayer.path = cornerBezierPath.CGPath; cornerShapLayer.lineWidth = 3.0; cornerShapLayer.strokeColor = [UIColor redColor].CGColor; cornerShapLayer.fillColor = UIColor.clearColor.CGColor; [_hudView.layer addSublayer:cornerShapLayer];
}
return _hudView;
}spa
3、扫描完成,对扫描结果进行分析和处理。通常一对一直播源码的扫描结果分为两种。
一、扫描结果分析成功,跳转相关页面
二、扫描结果解析失败,显示暂未识别出扫描结果。rest
(void)captureOutput:(AVCaptureOutput )captureOutput didOutputMetadataObjects:(NSArray )metadataObjects fromConnection:(AVCaptureConnection )connection {
if (metadataObjects != nil && metadataObjects.count > 0) {
AVMetadataMachineReadableCodeObject obj = metadataObjects[0];
NSDictionary infoDic = [self convertJsonStringToNSDictionary:[obj stringValue]];br/>NSLog(@"sweepcodeVC--------:%@",infoDic);
if ([[infoDic valueForKey:@"scope"] isEqual:@"laolaiwang"]) {
if ([minstr([[infoDic valueForKey:@"data"] valueForKey:@"type"]) isEqual:@"1"]) {
[_session stopRunning] ;
otherUserMsgVC person = [[otherUserMsgVC alloc]init];
person.userID = minstr([[infoDic valueForKey:@"data"] valueForKey:@"uid"]);
[self.navigationController pushViewController:person animated:YES];
}else if ([minstr([[infoDic valueForKey:@"data"] valueForKey:@"type"]) isEqual:@"2"]){
[self loginManagerWithDic:infoDic];
}code
}
} else {br/>NSLog(@"暂未识别出扫描的二维码");
}
}对象
以上就是一对一直播源码开发的扫描二维码功能的大致流程实现,该功能对于提升用户感觉和方便用户使用都有帮助,在万物皆可扫一扫的时代背景下,开发这个功能可以增强一对一直播源码开发加强社交性、互动性,知足人们的社交需求。ci