【发布时间】:2016-02-18 10:00:02
【问题描述】:
在 Objective-C 中你可以这样做:
if ( UIDeviceOrientationIsPortrait( deviceOrientation ) || UIDeviceOrientationIsLandscape( deviceOrientation ) ) {
AVCaptureVideoPreviewLayer *previewLayer = (AVCaptureVideoPreviewLayer *)self.previewView.layer;
previewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)deviceOrientation;
}
但是在 Swift 中,翻译最后一行的最佳方式是什么?你不能做“deviceOrientation as AVCaptureVideoOrientation”。
到目前为止我能想到的最好的方法是:
if(UIDeviceOrientationIsPortrait(deviceOrientation) || UIDeviceOrientationIsLandscape(deviceOrientation)) {
let myPreviewLayer: AVCaptureVideoPreviewLayer = self.previewLayer
myPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientation.init(rawValue: deviceOrientation.rawValue-1)!
}
但这似乎不优雅。 -1 在那里,因为它只是一天结束时的枚举,而 UIDeviceOrientation 枚举在位置 0 有一个“未知”,而 AVCaptureVideoOrientation 没有...
【问题讨论】:
标签: swift2 ios9 avcapturesession uideviceorientation ios9.1