UITableView自定义单元格轻触文本字段时自动滚动:Swift 3 [英] UITableView Custom Cell Auto scroll when text field is tapped : Swift 3
本文介绍了UITableView自定义单元格轻触文本字段时自动滚动:Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我使用了Custom UITableviewCell,每个单元格都有多个UItextfield,看起来像Cardview。
Here I used Custom UITableviewCell and each cell having multiple UItextfield and it's look like as Cardview.
当我点击添加图标时,将添加新的Cardview。
这里我不知道如何处理Autoscroll当我们点击Textfield时选项。
请在下面找到图片:
When I click Add icon New Cardview will be added. Here I don't know how to handle Autoscroll option when we click on Textfield. Please find below Image:
推荐答案
无需任何计算,使用下面的代码就能完美运行,
No need any calculations, use below code it will work perfectly,
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)
}
}
这篇关于UITableView自定义单元格轻触文本字段时自动滚动:Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文