当我的iPhone应用程序自动旋转时,我的相机方向错误

时间:2019-03-28 21:37:58

标签: ios swift xcode

我浏览了太多的文档。我根本找不到答案...据我所知... 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

            }
        }
    }
}

0 个答案:

没有答案