1
我有一個UITableView與「添加新項目」單元格的底部。當用戶點擊文本字段時,鍵盤出現並且tableview獲取內容插入,以使其底部始終位於鍵盤之上並且不隱藏在鍵盤之下。這已經幾乎完美了,但在鍵盤出現後,桌面視圖不再像以前那樣滾動到底部,它稍微高於底部,使得底部單元部分被鍵盤覆蓋。設置內容嵌入使UItableView滾動一點
設置內容的插圖,我註冊鍵盤的通知,並運行此代碼:
func adjustForKeyboard(notification: Notification) {
let userInfo = notification.userInfo!
let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame, from: view.window)
if notification.name == Notification.Name.UIKeyboardWillHide {
tableView.contentInset = UIEdgeInsets.zero
} else {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardViewEndFrame.height, right: 0)
}
tableView.scrollIndicatorInsets = tableView.contentInset
}
這裏也是一些截圖: