3
これは、カメラを背面から前面に切り替えるように見えますが、私は「if」ステートメントを思いついています。任意のアイデアやアドバイス?スウィフトのボタンでカメラを切り替える
@IBAction func didTouchSwitchButton(sender: UIButton) {
let camera = getDevice(.Front)
let cameraBack = getDevice(.Back)
do {
input = try AVCaptureDeviceInput(device: camera)
} catch let error as NSError {
print(error)
input = nil
}
if(captureSession?.canAddInput(input) == true){
captureSession?.addInput(input)
stillImageOutput?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]
if(captureSession?.canAddOutput(stillImageOutput) == true){
captureSession?.addOutput(stillImageOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.frame = cameraView.bounds
cameraView.layer.addSublayer(previewLayer!)
captureSession?.startRunning()
}
}
}
ありがとうございます!私はまだ.front .backを定義する問題が少しあります。これらの値は、それ自身では機能しないようです。 – craycades
私はあなたがgetDeviceのためにそれを使っているからだと思います。それを前方または後方またはそれに近い名前に変更してみてください – penatheboss
すべてがうまくいきますが、それでもカメラを切り替えることはできないようです。 – craycades