显示自动焦点矩形AVCaptureSession

时间:2015-04-16 06:47:28

标签: ios xcode video camera avcapturesession

我接近完成这项工作,我从这里获得了苹果示例代码https://github.com/master-nevi/WWDC-2010/tree/master/AVCamDemo,并且我正在尝试使用我想要的部件并且非常接近,但我可以完全理解它。当我点击时,我想让AVCaptureSession焦点在点击并显示一个矩形。我在这里:

- (void)drawFocusBoxAtPointOfInterest:(CGPoint)point
{
    NSDictionary *unanimatedActions = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"bounds",[NSNull null], @"frame",[NSNull null], @"position", nil];
   CALayer *focusBox = [[CALayer alloc] init];
    [focusBox setFrame:CGRectMake(0.f, 0.f, 100, 100)];
    [focusBox setPosition:point];
    [focusBox setBorderWidth:3.f];
    [focusBox setBorderColor:[[UIColor colorWithRed:0.f green:0.f blue:1.f alpha:.8f] CGColor]];
    [focusBox setOpacity:0.f];
    [PreviewLayer addSublayer:focusBox];
    [ViewController addAdjustingAnimationToLayer:focusBox removeAnimation:YES];
}    
}

这是PreviewLayer @property (retain) AVCaptureVideoPreviewLayer *PreviewLayer;

的地方

然后这是addAdjustingAnimationToLayer:focusBox

+ (void)addAdjustingAnimationToLayer:(CALayer *)layer removeAnimation:(BOOL)remove
{
if (remove) {
    [layer removeAnimationForKey:@"animateOpacity"];
}
if ([layer animationForKey:@"animateOpacity"] == nil) {
    [layer setHidden:NO];
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [opacityAnimation setDuration:.3f];
    [opacityAnimation setRepeatCount:1.f];
    [opacityAnimation setAutoreverses:YES];
    [opacityAnimation setFromValue:[NSNumber numberWithFloat:1.f]];
    [opacityAnimation setToValue:[NSNumber numberWithFloat:.0f]];
    [layer addAnimation:opacityAnimation forKey:@"animateOpacity"];
}
}

我在注册了一个点击时调用drawFocus,我知道该部分正在运行且正在调用函数drawFocus以及addAdjustingAnimation都被成功调用,我只是#39; t看到屏幕上出现了这个框?

如果你在你的应用程序中这样做有另一种方法可以做到这一点,如果你可以共享该代码,也将非常感激:)

感谢您的帮助。

0 个答案:

没有答案