0
フロントカメラをバックカメラに変更する必要があります。私はボタンを作成しようとすると、カメラを変更するが、それを行う方法ではない。これは私のコードです(このコードはフロントカメラを実行します):フロントカメラを交換する
var captureSession = AVCaptureSession()
var sessionOutput = AVCapturePhotoOutput()
var sessionOutputSetting = AVCapturePhotoSettings(format:[AVVideoCodecKey:AVVideoCodecJPEG])
var previewLayer : AVCaptureVideoPreviewLayer?
@IBOutlet var cameraView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
previewLayer?.frame = cameraView.bounds
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.unspecified)
for device in (deviceDiscoverySession?.devices)! {
if device.position == AVCaptureDevicePosition.back {
do {
let input = try AVCaptureDeviceInput(device: device)
if captureSession.canAddInput(input) {
captureSession.addInput(input)
if captureSession.canAddOutput(sessionOutput) {
captureSession.addOutput(sessionOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait
cameraView.layer.addSublayer(previewLayer!)
}
}
} catch {
print("Error")
}
}
}
captureSession.startRunning()
print("")
}
申し訳ありませんが、私はまだ初心者です。 SwiftyCam(https://github.com/Awalz/SwiftyCam)
http://stackoverflow.com/a/34470541/4475605 – Adrian
が重複する可能性に構文を変換することによって、それを使用することができます/stackoverflow.com/questions/34469189/how-to-switch-to-front-camera-in-swift-2) – shallowThought