Swift,让我参与其中:在iOS 8.0中不推荐使用interfaceOrientation

时间:2015-11-16 15:09:27

标签: ios swift ios9

这不是一个做或死,但没有任何运气与黑客这个。感谢。

  if session.canAddInput(videoDeviceInput){

    session.addInput(videoDeviceInput)

    self.videoDeviceInput = videoDeviceInput

    dispatch_async(dispatch_get_main_queue(), {

      // ERROR HERE
      let orientation: AVCaptureVideoOrientation =  AVCaptureVideoOrientation(rawValue: self.interfaceOrientation.rawValue)!

      (self.previewView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation = orientation

    })
  }

enter image description here

1 个答案:

答案 0 :(得分:5)

是的,它被贬低了。您可以改为使用UIApplication.sharedApplication().statusBarOrientation

let orientation: AVCaptureVideoOrientation?

switch UIApplication.sharedApplication().statusBarOrientation{
case .LandscapeLeft:
    orientation = .LandscapeLeft
case .LandscapeRight:
    orientation = .LandscapeRight
case .Portrait:
    orientation = .Portrait
case .PortraitUpsideDown:
    orientation = .PortraitUpsideDown
case .Unknown:
    orientation = nil
}

if let orientation = orientation{
    (self.previewView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation = orientation
}