相机方向没有改变

Camera orientation is not changed

我试过这个扫描条码的代码:

https://www.hackingwithswift.com/example-code/media/how-to-scan-a-barcode

但是它有一个错误,当我改变设备的方向时,相机总是有一个 Protrait 方向...

有什么解决办法吗?

我尝试用这种方法改变方向:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .Portrait
    }

但这并没有帮助。

您不希望使用该功能来改变相机的方向。改为这样做...

previewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait

这样做是在创建相机层时设置方向。