適配1: Cell點擊無效
在14上可能出現點擊cell上的視圖無法回應的情況.
原因:iOS14更改Cell視圖布局.將contentView放在最上層,如果將視圖加載在cell上,將會出現contentView遮罩,導致事件無法回應.是在此前關于 contentView 的宣告注釋中,官方已經明確建議開發者將 customView 放在 contentView 上,使 contentView 作為 UITableViewCell 默認的 fatherView,
解決辦法:
1、可以將cell子視圖加載在contentView上(提倡)
2、將contentView設定到最底層 self.sendSubviewToBack(self.contentView)
或者:通過Runtime簡單暴力的方式快速兼容了,原理就是在所有Cell addSubView()時,通過runtime攔截改為 contentView.addsubview(),代碼:
extension UITableViewCell {
class func ios14Bug() {
let sel1 = #selector(UITableViewCell.runtime_addSubview(_:))
let sel2 = #selector(UITableViewCell.addSubview(_:))
let method1 = class_getInstanceMethod(UITableViewCell.self, sel1)!
let method2 = class_getInstanceMethod(UITableViewCell.self, sel2)!
let isDid: Bool = class_addMethod(self, sel2, method_getImplementation(method1), method_getTypeEncoding(method1))
if isDid {
class_replaceMethod(self, sel1, method_getImplementation(method2), method_getTypeEncoding(method2))
} else {
method_exchangeImplementations(method2, method1)
}
}
@objc func runtime_addSubview(_ view: UIView) {
// 判斷不讓 UITableViewCellContentView addSubView自己
if view.isKind(of: NSClassFromString("UITableViewCellContentView")!) {
runtime_addSubview(view)
} else {
self.contentView.addSubview(view)
}
}
}
適配2:UIDatePicker 更新 UI 樣式
iOS 14 中,UIDatePicker UI樣式更新了
適配3:相冊權限
iOS14 新增了“Limited Photo Library Access” 模式,在授權彈窗中增加了 Select Photo 選項,用戶可以在 App 請求呼叫相冊時選擇部分照片讓 App 讀取,從 App 的視?來看,你的相冊里就只有這幾張照片,App 無法得知其它照片的存在,
重點!!!:權限提示框會在每次冷啟動后打開相冊時重新彈出,可以在 info.plist 中設定 PHPhotoLibraryPreventAutomaticLimitedAccessAlert 選項為 YES ,關閉提示
適配4:地理位置
新增了 精確定位 和 模糊定位 的概念,用戶可以手動選擇,模糊定位的誤差約 500m ,可以根據實際功能判斷是否可以接受用戶選擇模糊定位,
如果功能強依賴精確定位,可以在需要的時候呼叫 [CALocationMnanger requestTemporaryFullAccuracyAuthorizationWithPurposeKey:] 單獨請求一次精確定位,用戶可以選擇拒絕授權,所需引數 purposeKey 需要在 info.plist 中設定 NSLocationTemporaryUsageDescriptionDictionary 字典,key 為 purposeKey , value 為對應的話述
權限部分可以參考
iOS14更新內容及兼容設備
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/83782.html
標籤:其他
