我有一個具有多個文本框的UITableView。當我點擊文本框時,我將setContentOffset設置爲使文本框位於頁面的頂部,但當鍵盤出現時,我沒有足夠的插入框來執行此操作。所以我在插圖底部添加了插圖。這使我可以一直向下滾動,但現在當我選擇一個向下滾動的字段時,比我設置的setContentOffset更遠。我試過不同的內容插值,但沒有任何工作。有沒有辦法解決這個內容插入問題?UITableView滾動/插入問題
func adjustInsetForKeyboardShow(_ show: Bool, notification: Notification) {
if !keyboardAdjusted || !show {
guard let value = (notification as NSNotification).userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardFrame = value.cgRectValue
var adjustmentHeight = (keyboardFrame.height + 100) * (show ? 1 : -1)
adjustmentHeight = (adjustmentHeight < 0.0) ? 0.0 : adjustmentHeight
self.editPaymentTableView.contentInset.bottom = adjustmentHeight
self.editPaymentTableView.scrollIndicatorInsets.bottom = adjustmentHeight
}
keyboardAdjusted = show
}
如果你想使用框架[IQKeyboardManager](https://github.com/hackiftekhar/IQKeyboardManager)可以幫助,易於使用。 –