ios 10.2ですばやく3でSnapchatのようなカメラを作成しようとしましたが、問題はiPhoneでアプリを実行するときです。 UIViewが空に見えます。これは私のコードです。私のInfo.plistでカメラios 10.2、swift 3
import UIKit
import AVFoundation
class TakeSelfieViewController: UIViewController {
@IBOutlet var cameraView: UIView!
var captureSession : AVCaptureSession?
var stillImageOutput: AVCaptureStillImageOutput?
var previewLayer : AVCaptureVideoPreviewLayer?
override func viewDidLoad() {
super.viewDidLoad()
captureSession = AVCaptureSession()
captureSession?.sessionPreset = AVCaptureSessionPreset1920x1080
let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.front)
for device in (deviceDiscoverySession?.devices)! {
if device.position == AVCaptureDevicePosition.front{
do {
let input = try AVCaptureDeviceInput(device: device)
if (captureSession?.canAddInput(input))!{
captureSession?.addInput(input)
stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput?.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG]
if (captureSession?.canAddOutput(stillImageOutput))! {
captureSession?.addOutput(stillImageOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait
cameraView.layer.addSublayer(previewLayer!)
captureSession?.startRunning()
}
}
} catch{
print("Error Occured when trying get camera")
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var prefersStatusBarHidden: Bool {
return true
}
私はプライバシーを追加している - カメラの使用説明
何が起こっていますか?
説明を正しく追加しますか? – BilalReffas
これを見てくださいhttp://stackoverflow.com/questions/37869963/how-to-use-avcapturephotooutput/38171414#38171414 – BilalReffas
カメラマネージャーでカメラセッションを処理できる簡単なクラスがあります。あなたはそれにカメラのpreviewlayerを表示するビュー:https://github.com/maryamfekri/MFCameraManager –