我正在尝试将 AVCaptureVideoPreviewLayer CALayer 作为背景添加到我的 SKScene。我可以将 CALayer 添加到场景中,但无论尝试如何订购 CALayer 始终是最顶层的对象。
在 didMoveToView 我有这个功能:
- (void) didMoveToView:(SKView *)view
{
[self addVideo];
}
调用 addVideo 函数:
-(void) addVideo {
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
captureSession.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
[captureSession addInput:videoIn];
AVCaptureVideoPreviewLayer *avLayer =
[AVCaptureVideoPreviewLayer layerWithSession:captureSession];
avLayer.frame = self.view.bounds;
CGSize landscapeSize;
landscapeSize.width = self.view.bounds.size.height;
landscapeSize.height = self.view.bounds.size.width;
CGRect landscapeRect;
landscapeRect.size = landscapeSize;
landscapeRect.origin = self.view.bounds.origin;
avLayer.frame = landscapeRect;
if(avLayer.connection.supportsVideoOrientation)
{
avLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
}
[self.scene.view.layer insertSublayer:avLayer atIndex:0];
[self.scene.view.layer setNeedsLayout];
[captureSession startRunning];
}
我尝试了多种方法将 AVCaptureVideoPreviewLayer CALayer 作为背景。每次将节点添加到场景中时,它都位于此 CALayer 之上,有什么建议吗?
尝试了以下功能:
- (void) sendSublayerToBack:(CALayer *)layer
{
[layer removeFromSuperlayer];
[self.view.layer insertSublayer:layer atIndex:0];
}
但仍然无法正常工作......