我浏览了太多的文档。我根本找不到答案...据我所知... Apple文档是一半的垃圾,真让我感到惊讶...
每次旋转相机时,用户界面都会明显旋转,但相机保持旋转状态...
就像坐标仍然是局部的,而不是面向全球的北部
我希望我能很好地说明自己
我不知道还要查什么
import UIKit
import AVFoundation
class scannerViewController: UIViewController {
var session : AVCaptureSession!
var input : AVCaptureInput!
var previewLayer : AVCaptureVideoPreviewLayer!
var camera : AVCaptureDevice!
@IBOutlet weak var cameraPreview: UIView!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
session = AVCaptureSession()
camera = AVCaptureDevice.default(for: AVMediaType.video)
input = try? AVCaptureDeviceInput(device: camera!)
session.addInput(input)
previewLayer = AVCaptureVideoPreviewLayer(session: session)
cameraPreview.layer.addSublayer(previewLayer)
DispatchQueue.global(qos: .userInitiated).async {
self.session.startRunning()
DispatchQueue.main.async {
self.previewLayer.frame = self.cameraPreview.bounds
}
}
}
}