Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This sounds very complex at first to me... but it turned super simple, Apple already did the 99% of work for us. All you need to do is to set "<a href="http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html">subjectAreaChangeMonitoringEnabled</a>" on and register KVO on "AVCaptureDeviceSubjectAreaDidChangeNotification"! On the iOS 6.1 docs:</p> <blockquote> <p>The value of this property indicates whether the receiver should monitor the video subject area for changes, such as lighting changes, substantial movement, and so on. If subject area change monitoring is enabled, the capture device object sends an AVCaptureDeviceSubjectAreaDidChangeNotification whenever it detects a change to the subject area, at which time an interested client may wish to re-focus, adjust exposure, white balance, etc.</p> <p>Before changing the value of this property, you must call lockForConfiguration: to acquire exclusive access to the device’s configuration properties. If you do not, setting the value of this property raises an exception. When you are done configuring the device, call unlockForConfiguration to release the lock and allow other devices to configure the settings.</p> <p>You can observe changes to the value of this property using key-value observing.</p> </blockquote> <p>(Even better, you don't need to handle many corner cases. What if the device is in the middle of "adjustingFocus" at a POI and the content changed? You don't want the device fall back to auto focus at the center, and want the focus action to finish. The "area did change notification" is only triggered after the focus is done.) </p> <p>Some sample code snippet from my project. (The structure follows the official AVFoundation example AVCam, so you can put them in easily and try out):</p> <pre><code>// CameraCaptureManager.m @property (nonatomic, strong) AVCaptureDevice *backFacingCamera; - (id) init{ self = [super init]; if (self){ // TODO: more of your setup code for AVFoundation capture session for (AVCaptureDevice *device in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { if (device.position == AVCaptureDevicePositionBack){ self.backFacingCamera = device; } } NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; void (^subjectAreaDidChangeBlock)(NSNotification *) = ^(NSNotification *notification) { if (self.videoInput.device.focusMode == AVCaptureFocusModeLocked ){ // All you need to do is set the continuous focus at the center. This is the same behavior as // in the stock Camera app [self continuousFocusAtPoint:CGPointMake(.5f, .5f)]; } }; self.subjectAreaDidChangeObserver = [notificationCenter addObserverForName:AVCaptureDeviceSubjectAreaDidChangeNotification object:nil queue:nil usingBlock:subjectAreaDidChangeBlock]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [self addObserver:self forKeyPath:keyPathAdjustingFocus options:NSKeyValueObservingOptionNew context:NULL]; } return self; } -(void) dealloc{ // Remove the observer when done NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter removeObserver:self.deviceOrientationDidChangeObserver]; } - (BOOL) setupSession{ BOOL sucess = NO; if ([self.backFacingCamera lockForConfiguration:nil]){ // Turn on subject area change monitoring self.backFacingCamera.subjectAreaChangeMonitoringEnabled = YES; } [self.backFacingCamera unlockForConfiguration]; // TODO: Setup add input etc... return sucess; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload