Ios 如何在cameraView中显示扫描动画

Ios 如何在cameraView中显示扫描动画,ios,objective-c,avcapturesession,Ios,Objective C,Avcapturesession,当用户打开应用程序时,我正在加载cameraview,这里我需要显示扫描动画,如条形码扫描。是否有任何方法可以使用AVCaptureSession在cameraView上显示动画 [self setCaptureSession:[[AVCaptureSession alloc] init]]; [self addVideoInputFrontCamera:NO]; // set to YES for Front Camera, No for Back camera [self ad

当用户打开应用程序时,我正在加载cameraview,这里我需要显示扫描动画,如条形码扫描。是否有任何方法可以使用AVCaptureSession在cameraView上显示动画

[self setCaptureSession:[[AVCaptureSession alloc] init]];


 [self  addVideoInputFrontCamera:NO]; // set to YES for Front Camera, No for Back camera

 [self  addStillImageOutput];

 [self setPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]] ];



 [[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];



 CGRect layerRect = [[[self view] layer] bounds];


 [[self previewLayer]setBounds:layerRect];
 [[self  previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
 [[[self view] layer] addSublayer:[self  previewLayer]];

 [[self captureSession] startRunning];

创建一个scanninglayer并将此子层添加到预览层,使用图像数组在持续时间内扫描动画

例如:

 CALayer *layerGun=[CALayer layer];
 layerGun.bounds=CGRectMake(0.0, 0.0, 704,500);
 [layerGun setPosition:CGPointMake(512,250)];
 [layerGun setContents:(id)[UIImage imageNamed:@" Right0001.png"].CGImage];
 layerGun.zPosition=5;
 NSString *animationkey=[NSString stringWithFormat:@"animate%d",i+1];
 NSString *animationkey2=[NSString stringWithFormat:@"position%d",i+1];
 CAKeyframeAnimation *layerAnimation1 = [CAKeyframeAnimation animation];
 layerAnimation1.calculationMode = kCAAnimationLinear;
 layerAnimation1.beginTime=begantimeone-bgntime;
 layerAnimation1.duration = 0.3;
 layerAnimation1.delegate=self;
 layerAnimation1.keyPath=@"contents";
 layerAnimation1.values = [NSArray arrayWithObjects:
      (id)[[UIImage imageNamed:@"Right0001.png"] CGImage],
      (id)[[UIImage imageNamed:@"Center0003.png"] CGImage],
      (id)[[UIImage imageNamed:@"Center0004.png"] CGImage],
      (id)[[UIImage imageNamed:@"Center0005.png"] CGImage],
      (id)[[UIImage imageNamed:@"Center0006.png"] CGImage], nil];

 [layerGun addAnimation:layerAnimation1 forKey:animationkey];
希望这个有帮助

      CGPoint start = CGPointMake(startX, 0);
      CGPoint end = CGPointMake(startX, self.view.frame.size.height+10);    
      CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
      animation.delegate = self;
      animation.fromValue = [NSValue valueWithCGPoint:start];
      animation.toValue = [NSValue valueWithCGPoint:end];
      animation.duration = 10*speed;

      //animation.repeatCount = repeatCount;
      animation.autoreverses = NO;
      animation.removedOnCompletion   = YES;
      animation.fillMode = kCAFillModeForwards;

      [layer addAnimation:animation forKey:@"position"];

是的,你可以在你的相机视图上方设置一个覆盖视图,并为几组复制条形码扫描的图像设置动画是的,我知道这一点。但我正在寻找显示扫描动画的代码,这行代码将做什么layerAnimation1.beginTime=BeginTimeOne gmtime;?我正在使用undeclaredhere你只是给开始时间作为开始时间删除这些BeginTimeOne gmtimeI我有image name line.png。我需要显示这个图像作为扫描动画从下到上