AVCaptureVideoPreviewLayer розовый на iPhone XR - PullRequest
0 голосов
/ 27 мая 2020

У нас есть AVCaptureVideoPreviewLayer, который должен отображать изображение с камеры. На iPhone 10 (и iPhone 7) изображение отображается правильно. Однако на iPhone XR он отображается розовым.

Вот мой код, как я настраиваю сеанс камеры:

UIView* scanView = [[UIView alloc]initWithFrame:[self view].frame];
[self setCameraScanView:scanView];
[[self cameraScanView]setContentMode:UIViewContentModeScaleAspectFit];
[self setScanCaptureSession:[[AVCaptureSession alloc] init]];
[[self scanCaptureSession]setSessionPreset:AVCaptureSessionPresetLow];
AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[[videoOutput connectionWithMediaType:AVMediaTypeVideo]setEnabled:YES];
[videoOutput setAlwaysDiscardsLateVideoFrames:YES];
[videoOutput setSampleBufferDelegate:self
        queue:dispatch_get_main_queue()];
[[self scanCaptureSession]addOutput:videoOutput];
NSError* error;
AVCaptureDeviceInput* input = [[AVCaptureDeviceInput alloc]
        initWithDevice:camera error:&error];
[[self scanCaptureSession]addInput:input];
if(error) {
    NSLog(@"There was an error setting up Device Input!");
}
AVCaptureVideoPreviewLayer* previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:[self scanCaptureSession]];
[self setCameraLayer:previewLayer];
[[self cameraLayer] setContentsFormat:kCAContentsFormatRGBA16Float];
[[self cameraLayer] setOpaque:YES];
CALayer* rootLayer = [[self cameraScanView]layer];
[[self cameraLayer]setFrame:[self cameraScanView].bounds];
[[self cameraLayer]setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[rootLayer addSublayer:[self cameraLayer]];
[[self scanCaptureSession]commitConfiguration];
[[self view] addSubview:[self cameraScanView]];

Вот изображение, как это выглядит на iPhone XR .
enter image description here

...