###前提・実現したいこと
ここに質問したいことを詳細に書いてください
swiftでカメラを追加いたいのですが、サイズの調整がうまくいきません。
UIViewと同じサイズでカメラ画面を表示したいのですが、画面が小さくなったりして
うまくいきません
よろしくお願いします。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
import UIKit import AVFoundation class ViewController: UIViewController, AVCapturePhotoCaptureDelegate { // カメラの映像をここに表示 @IBOutlet weak var cameraView: UIView! var captureSesssion: AVCaptureSession! var stillImageOutput: AVCapturePhotoOutput? var previewLayer: AVCaptureVideoPreviewLayer? override func viewWillAppear(_ animated: Bool) { captureSesssion = AVCaptureSession() stillImageOutput = AVCapturePhotoOutput() captureSesssion.sessionPreset = AVCaptureSessionPreset1920x1080 // 解像度の設定 let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) do { let input = try AVCaptureDeviceInput(device: device) // 入力 if (captureSesssion.canAddInput(input)) { captureSesssion.addInput(input) // 出力 if (captureSesssion.canAddOutput(stillImageOutput)) { captureSesssion.addOutput(stillImageOutput) captureSesssion.startRunning() // カメラ起動 previewLayer = AVCaptureVideoPreviewLayer(session: captureSesssion) // previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect // アスペクトフィット previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait // カメラの向き self.cameraView.layer.addSublayer(previewLayer!) // ビューのサイズの調整 previewLayer?.frame = cameraView.bounds } } } catch { print(error) } } }
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
AVCaptureSessionPreset1920x1080を設定しているので、UIViewと同じサイズでカメラ画面を表示させる場合はUIViewからはみ出たり小さくなったりしますが
あなたの回答
tips
プレビュー