#pragma mark 初始化扫描
- (void)InitScan
{
readview = [ZBarReaderView new];
readview.backgroundColor = [UIColor clearColor];
readview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
readview.readerDelegate = self;
readview.allowsPinchZoom = YES;//使用手势变焦
readview.trackingColor = [UIColor redColor];
readview.showsFPS = NO;// 显示帧率 YES 显示 NO 不显示
//readview.scanCrop = CGRectMake(0, 0, 1, 1);//将被扫描的图像的区域
UIImage *hbImage=[UIImage imageNamed:@"pick_bg.png"];
scanZomeBack=[[UIImageView alloc] initWithImage:hbImage];
//添加一个背景图片
CGRect mImagerect=CGRectMake((readview.frame.size.width-200)/2.0, (readview.frame.size.height-200)/2.0, 200, 200);
[scanZomeBack setFrame:mImagerect];
readview.scanCrop = [self getScanCrop:mImagerect readerViewBounds:readview.bounds];//将被扫描的图像的区域
[readview addSubview:scanZomeBack];
[readview addSubview:readLineView];
[self.view addSubview:readview];
[readview start];
}
#pragma mark 获取扫描区域
-(CGRect)getScanCrop:(CGRect)rect readerViewBounds:(CGRect)readerViewBounds
{
CGFloat x,y,width,height;
x = rect.origin.x / readerViewBounds.size.width;
y = rect.origin.y / readerViewBounds.size.height;
width = rect.size.width / readerViewBounds.size.width;
height = rect.size.height / readerViewBounds.size.height;
return CGRectMake(x, y, width, height);
}
#pragma mark 扫描动画
-(void)loopDrawLine
{
CGRect rect = CGRectMake(scanZomeBack.frame.origin.x, scanZomeBack.frame.origin.y, scanZomeBack.frame.size.width, 2);
if (readLineView) {
[readLineView removeFromSuperview];
}
readLineView = [[UIImageView alloc] initWithFrame:rect];
[readLineView setImage:[UIImage imageNamed:@"line.png"]];
[UIView animateWithDuration:3.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
//修改fream的代码写在这里
readLineView.frame =CGRectMake(scanZomeBack.frame.origin.x, scanZomeBack.frame.origin.y+scanZomeBack.frame.size.height, scanZomeBack.frame.size.width, 2);
[readLineView setAnimationRepeatCount:0];
}
completion:^(BOOL finished){
if (!is_Anmotion) {
[self loopDrawLine];
}
}];
[readview addSubview:readLineView];
}
#pragma mark 获取扫描结果
- (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
// 得到扫描的条码内容
const zbar_symbol_t *symbol = zbar_symbol_set_first_symbol(symbols.zbarSymbolSet);
NSString *symbolStr = [NSString stringWithUTF8String: zbar_symbol_get_data(symbol)];
if (zbar_symbol_get_type(symbol) == ZBAR_QRCODE) {
// 是否QR二维码
}
for (ZBarSymbol *symbol in symbols) {
[sTxtField setText:symbol.data];
break;
}
[readerView stop];
[readerView removeFromSuperview];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-3 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.yuanmawang.com) 版权所有