我正在尝试将 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];
}
但还是不行....
不要在 SKView 层中显示该层 - 创建另一个 UIView 并将其放置在视图层次结构中,使其位于 SKView 后面。然后将视频层添加到该 UIView。
你必须使 SKView 透明,尽管在这里我不确定这是否有效 - 如果它完全像 cocos2d 一样工作:将 opaque 属性设置为 NO 并将 backgroundColor 属性更改为 nil (如果还没有 nil) 。这应该使 SKView 透明。
如果这些都不起作用,也许您可以找到使用 SKVideoNode 的解决方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)