title: Show Auto Focus Rectangle AVCaptureSession
body: <p>I am close to having this work, I have the apple sample code from here <a href="https://github.com/master-nevi/WWDC-2010/tree/master/AVCamDemo" rel="nofollow">https://github.com/master-nevi/WWDC-2010/tree/master/AVCamDemo</a> and am trying to use the parts I want and am very close but I can quite get it. When I tap I want to have the AVCaptureSession focus where tapped and show a rectangle. Here what I have: </p>
  
  <pre><code>- (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];
  }    
  }
  </code></pre>
  
  <p>This is where PreviewLayer is <code>@property (retain) AVCaptureVideoPreviewLayer *PreviewLayer;</code></p>
  
  <p>Then this is <code>addAdjustingAnimationToLayer:focusBox</code></p>
  
  <pre><code>+ (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"];
  }
  }
  </code></pre>
  
  <p>And I call <code>drawFocus</code> when a tap is registered and I know that part is working and the function <code>drawFocus</code> is being called as well as <code>addAdjustingAnimation</code> are both successfully called, I just don't see the box appear on the screen?</p>
  
  <p>If you are doing this in your app have another way to do it, that would also be greatly appreciated if you could share that code :)</p>
  
  <p>Thanks for the help in advance.</p>