1

我正在尝试在我的中画线SKScene,我可以成功地画出它,但我想要那条线在前面,AVCapturePreviewLayer但我得到了这样的东西:

在此处输入图像描述

我想要我的 cameraPreviewLayer 上方的所有行。

这是我的代码:

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 但它不起作用。

这是我的示例项目。

4

0 回答 0