使用键盘向上移动 UITextField - swift 4.2 中的更改?

Moving UITextField up with keyboard - changes in swift 4.2?

我有这个功能可以向上移动某些文本字段,当键盘会挡住他们的视线时 - 我相信你们都知道这个:

override func viewDidLoad() {
    super.viewDidLoad()

    let center: NotificationCenter = NotificationCenter.default
    center.addObserver(self, selector: #selector(keyboardDidShow(notification:)), name: NSNotification.Name?.UIKeyboardDidShow, object: nil)
    center.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: NSNotification.Name?.UIKeyboardWillHide, object: nil)

}

但是当我最近更新到 swift 4.2 时,这些都停止工作了,出现了这些建议:

将'UIKeyboardDidShow'替换为'UIResponder.keyboardDidShowNotification' &

将'UIKeyboardWillHide'替换为'UIResponder.keyboardWillHideNotification

但是当我按下 "fix" 时,出现错误 (x2):

类型 'NSNotification.Name' 没有成员 'UIResponder'

我觉得这有点像错误? xCode 不能接受它自己的改变??有人遇到过这个并且知道该怎么做吗?

谢谢!

试试这个

let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification object: nil)

更多信息使用此 link :- enter link description here

希望对您有所帮助:D 谢谢