簡體   English   中英

Swift,讓我着迷於此:iOS 8.0中不推薦使用interfaceOrientation

[英]Swift, has got me on this one: interfaceOrientation was deprecated in iOS 8.0

這不是一成不變的事情,但是對於黑客入侵並沒有任何運氣。 謝謝。

  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

    })
  }

在此處輸入圖片說明

是的,它已經廢止了。 您可以改用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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM