iphone相机的曝光/对焦锁定:不会保持锁定状态

问题描述

|| 我正在尝试使用iPhone相机以编程方式从同一场景拍摄多张照片,但我不想在用户将其设置为第一张照片后改变曝光或焦点。 这是我的代码,当用户从我的应用程序内启动图片拍摄时会执行:
        NSArray *devices = [AVCaptureDevice devices];
    NSError *error;
    for (AVCaptureDevice *device in devices) {
        if (([device hasMediaType:AVMediaTypeVideo]) && 
            ([device position] == AVCaptureDevicePositionBack) ) {
            [device lockForConfiguration:&error];
            if ([device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked]) {
                device.whiteBalanceMode = AVCaptureWhiteBalanceModeLocked;
                NSLog(@\"Whitebalanced locked\");
            }
            if ([device isExposureModeSupported:AVCaptureExposureModeLocked]) {
                device.exposureMode = AVCaptureExposureModeLocked;
                NSLog(@\"Exposure locked\");
            }

             if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
             device.focusMode = AVCaptureFocusModeLocked;
             NSLog(@\"Focus locked\");
             }

            [device unlockForConfiguration];
        }
    }
问题:拍摄第一张照片后,相机会自动对焦和自动曝光。如何强制曝光和对焦保持锁定状态? 任何帮助表示赞赏。     

解决方法

        我认为您缺少提交配置的方法: 在您的代码之前:
captureSession = [[AVCaptureSession alloc] init];
[captureSession beginConfiguration];
后:
[captureSession commitConfiguration];
希望这会有所帮助。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...