iPhone X發(fā)布了,價格感人,但總有土豪會買。有人用就得適配,個人感覺,齊劉海不丑。

下載Xcode 9
? ? 蘋果開發(fā)者網(wǎng)站可以下載Xcode9 GM版本了,如果要保留Xcode8,需要先把Xcode.app修改為Xcode8.app,然后再安裝Xcode9,這樣就可以同時擁有兩個版本了。
Swift 4.0 遷移
? ? 首先,第三方庫要支持Swift 4.0。
? ? 對于業(yè)務(wù)代碼,選擇菜單“Edit > Convert > To Current Swift Syntax...”,竟然沒有當(dāng)前項目的選項,只能選擇Test項目。作罷,直接編譯,有錯就改吧?!?/p>
【錯誤一】Argument of '#selector' refers to instance method 'XXXXXXX' that is not exposed to Objective-C
【解決方法】聰明的Xcode也給出了提示——Add '@objc' to expose this instance method to Objective-C,直接點擊fix按鈕,Xcode自動修改問題?!?/p>
【錯誤二】'NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font'
【解決方法】一些類被重新命名,Xcode提示——Replace 'NSFontAttributeName' with 'NSAttributedStringKey.font',直接點擊fix按鈕,一直點、點、點......手殘了......————————————————————————————————————
【錯誤三】Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey'

【解決方法】將[NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],改為[NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]———————————————————————————————————
【錯誤四】'priority' produces 'ConstraintMakerFinalizable', not the expected contextual result type 'Void'

【解決方法】將UILayoutPriorityDefaultHigh,修改為UILayoutPriority.defaultHigh.rawValue。同理,根據(jù)錯誤替換其他的枚舉項,包括UILayoutPriority.required.rawValue、UILayoutPriority.defaultLow.rawValue?!?/p>
【錯誤五】其實是個警告:'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.
【解決方法】substring被廢棄,使用下標(biāo)來截取字符串。
例如rgba.substring(from: index)改為String(rgba[index...])?!?/p>
iPhone X適配
? ? ? 改完所有錯誤,編譯運行,齊劉海迎面而來,竟然適配的如此完美。明顯的問題只發(fā)現(xiàn)一處,左上角的返回按鈕,點擊無響應(yīng)。

? ? ? 將按鈕往下調(diào)整30個點,點擊可以正常響應(yīng)了。由此推斷,應(yīng)該是左上角的太陽穴位置,不響應(yīng)手勢了。
? ? ? iPhone X,余生請多指教!