키보드가 나타나거나 사라질 때주의를 기울여 그에 따라 tableView의 contentInset
을 설정해야합니다.
override func viewDidLoad() {
super.viewDidLoad()
...
// register the responders
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)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
:
ViewDidLoad
및
deinit
의 대응을 등록 해제/
func keyBoardWillShow(notification: NSNotification) {
if let keyBoardSize = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? CGRect {
let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyBoardSize.height, right: 0)
self.tableView.contentInset = contentInsets
}
}
func keyBoardWillHide(notification: NSNotification) {
self.tableView.contentInset = UIEdgeInsets.zero
}
을 그리고 등록 : 당신의 TableViewController 클래스에서
키보드 이벤트에 조치로 두 가지 기능을 만들