在開發(fā)過程中遇到tableView內(nèi)容下移20pt或下移64pt的問題,對當(dāng)tableView超出安全區(qū)域時系統(tǒng)自動調(diào)整了SafeAreaInsets
值,進(jìn)而影響adjustedContentInset
值弦撩,在iOS 11中決定tableView的內(nèi)容與邊緣距離的是adjustedContentInset
屬性力奋,而不是contentInset
驼修。
adjustedContentInset = safeAreaInset + contentInset
在 UIViewContoller 實現(xiàn) viewSafeAreaInsetsDidChange
方法
override func viewSafeAreaInsetsDidChange() {
if #available(iOS 11.0, *) {
super.viewSafeAreaInsetsDidChange()
NSLog("viewSafeAreaInsetsDidChange-%@",NSStringFromUIEdgeInsets(self.view.safeAreaInsets))
} else {
// Fallback on earlier versions
}
self.updateOrientation()
}
對應(yīng)的 updateOrientation() 方法內(nèi)容為
/**
更新屏幕safearea frame
*/
func updateOrientation()
{
if #available(iOS 11.0, *) {
var frame = self.customView.frame
frame.origin.x = self.view.safeAreaInsets.left
frame.size.width = self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right
frame.size.height = self.view.frame.size.height - self.view.safeAreaInsets.bottom
self.customView.frame = frame
}
}