Как я могу установить слой предварительного просмотра AVCapture в качестве фона набора спрайтов?
Я пытаюсь нарисовать линии в моем SKScene
и я могу успешно нарисовать его, но я хочу, чтобы линии перед AVCapturePreviewLayer
но я получаю что-то вроде этого:
Я хочу, чтобы все строки над моей камерой PrevLayer.
и это мой код для этого:
import SpriteKit
import UIKit
import AVFoundation
class GameScene: SKScene {
let captureSession = AVCaptureSession()
var shapeCross:SKShapeNode!
var error: NSError?
override func didMoveToView(view: SKView) {
let devices = AVCaptureDevice.devices().filter{ $0.hasMediaType(AVMediaTypeVideo) && $0.position == AVCaptureDevicePosition.Back }
if let captureDevice = devices.first as? AVCaptureDevice {
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &error))
captureSession.sessionPreset = AVCaptureSessionPresetPhoto
captureSession.startRunning()
if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) {
previewLayer.bounds = CGRectMake(0.0, 0.0, 100, 100)
previewLayer.position = CGPointMake(view.bounds.midX, view.bounds.midY)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.opacity = 1
view.scene?.backgroundColor = UIColor.clearColor()
view.layer.addSublayer(previewLayer)
}
}
let bezierPath = UIBezierPath(rect: CGRect(x: 0, y: view.scene!.frame.midY, width: view.scene!.frame.width, height: 1))
bezierPath.appendPath( UIBezierPath(rect: CGRect(x: view.scene!.frame.midX, y: 0, width: 1, height: view.scene!.frame.height)) )
shapeCross = SKShapeNode(path: bezierPath.CGPath)
shapeCross.strokeColor = UIColor.whiteColor()
self.addChild(shapeCross)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
}
override func update(currentTime: CFTimeInterval) {
}
}
Я хочу мое previewLayer
за моим SKScene
после этого я хочу сделать что-то вроде этого:
view.scene?.backgroundColor = UIColor.clearColor()
Так я вижу previewLayer
и я тоже вижу свои строки.
Я пытаюсь установить zPosition просмотров, но это не работает.
Это мой пример проекта.