当我的用户点击聚焦时,我注册了AVCaptureDeviceSubjectAreaDidChangeNotification
的通知,这是我的代码:
CGPoint autofocusPoint = CGPointMake(xValue, yValue);
[device setFocusPointOfInterest:autofocusPoint];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
CGPoint exposurePoint = CGPointMake(xValue, yValue);
[device setExposurePointOfInterest:exposurePoint];
[device setExposureMode:AVCaptureExposureModeAutoExpose];
RCTLogWarn(@"DID autofocusand autoexpose");
if (!self.isFocusedOnPoint) {
self.isFocusedOnPoint = true;
RCTLogWarn(@"clog: ok add listener");
device.subjectAreaChangeMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AutofocusDelegate:) name:AVCaptureDeviceSubjectAreaDidChangeNotification object:device];
}
}
但是,如果我快速移动设备,快速更改相机视图的主题,则不会触发通知。我必须移动设备,直到最终看到此触发器。有人遇到这个问题吗?
在我的通知代表中,我撤消了点击以专注于以下目的:
AVCaptureDevice *device = [self.videoCaptureDeviceInput device];
if (self.isFocusedOnPoint) {
RCTLogWarn(@"clog: ok remove listener");
self.isFocusedOnPoint = false;
CGPoint autofocusPoint = CGPointMake(0.5f, 0.5f);
CGPoint exposurePoint = CGPointMake(0.5f, 0.5f);
[device setExposurePointOfInterest: autofocusPoint];
[device setFocusPointOfInterest: exposurePoint];
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceSubjectAreaDidChangeNotification object:device];
device.subjectAreaChangeMonitoringEnabled = NO;
}