二維碼功能方便快捷,深受用戶喜好,本文爲你們簡單介紹,一對一直播系統開發想要實如今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