UITableView自定义单元格轻触文本字段时自动滚动:Swift 3

在这里,我使用Custom UITableviewCell,每个单元格都有多个UItextfield,它看起来像Cardview。

当我单击添加图标时,将添加新的Cardview。 在单击Textfield时,我不知道如何处理Autoscroll选项。 请在下面找到图片:

在此处输入图像描述

无需任何计算,使用下面的代码它将完美地工作,

override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) } func keyboardWillShow(_ notification:Notification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { reimbursementTableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0) } } func keyboardWillHide(_ notification:Notification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { reimbursementTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) } }