当键盘会阻止它们的视图时,我具有向上移动某些文本字段的功能-我相信大家都知道这一点:
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时,这些停止了工作,并且出现了以下建议:
用'UIResponder.keyboardDidShowNotification'替换'UIKeyboardDidShow'&
将'UIKeyboardWillHide'替换为'UIResponder.keyboardWillHideNotification
但是当我按下“修复”时,出现错误(x2):
类型“ NSNotification.Name”没有成员“ UIResponder”
对我来说,这似乎是个虫子?那个xCode不能接受它自己的改变?有人碰到这个,知道该怎么办吗?
谢谢!
答案 0 :(得分:1)
尝试一下
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)
更多信息请使用此链接:-enter link description here
我希望这会对您有所帮助:D 谢谢