2017-09-25 71 views
1

在從會話506的WWDC 2017年視頻有一個在第一演示看起來像這樣一塊代碼:關於蘋果WWDC 2017會話506的代碼摘錄 - exifOrientationFromDeviceOrientation()在哪裏定義?

let exifOrientation = self.exifOrientationFromDeviceOrientation() 

使用自我。表明它應該是ViewController的一個屬性。鑑於這個方法在UIViewController類中不存在,我認爲ViewController符合授予該功能的協議。有人可以指出哪個協議是?

回答

1

我強烈建議你看看https://github.com/yulingtianxia/Core-ML-Sample/blob/master/CoreMLSample/ViewController.swift,它是GitHub上Core-ML-Sample項目的一部分。

var exifOrientationFromDeviceOrientation: Int32 { 
    let exifOrientation: DeviceOrientation 
    enum DeviceOrientation: Int32 { 
     case top0ColLeft = 1 
     case top0ColRight = 2 
     case bottom0ColRight = 3 
     case bottom0ColLeft = 4 
     case left0ColTop = 5 
     case right0ColTop = 6 
     case right0ColBottom = 7 
     case left0ColBottom = 8 
    } 
    switch UIDevice.current.orientation { 
    case .portraitUpsideDown: 
     exifOrientation = .left0ColBottom 
    case .landscapeLeft: 
     exifOrientation = .top0ColLeft 
    case .landscapeRight: 
     exifOrientation = .bottom0ColRight 
    default: 
     exifOrientation = .right0ColTop 
    } 
    return exifOrientation.rawValue 
} 

乾杯!

1

你是指這個代碼posted here

他們在代碼中創建變量:

var exifOrientationFromDeviceOrientation: Int32 { 
    let exifOrientation: DeviceOrientation 
    enum DeviceOrientation: Int32 { 
     case top0ColLeft = 1 
     case top0ColRight = 2 
     case bottom0ColRight = 3 
     case bottom0ColLeft = 4 
     case left0ColTop = 5 
     case right0ColTop = 6 
     case right0ColBottom = 7 
     case left0ColBottom = 8 
    } 
    switch UIDevice.current.orientation { 
    case .portraitUpsideDown: 
     exifOrientation = .left0ColBottom 
    case .landscapeLeft: 
     exifOrientation = .top0ColLeft 
    case .landscapeRight: 
     exifOrientation = .bottom0ColRight 
    default: 
     exifOrientation = .right0ColTop 
    } 
    return exifOrientation.rawValue 
} 
+0

感謝您的迴應,CodeBender。感謝您能否指點我可以找到完整代碼的位置。最好的祝福。 –

+0

@AndreGuerra我發佈了鏈接。你可以在我的答案中找到「張貼在這裏:」。 – CodeBender

+0

o.O - 我的不好。之前沒有注意到它。 THKS。 –