问题描述
当键盘会阻止它们的视图时,我具有向上移动某些文本字段的功能-我相信大家都知道这一点:
I had this function to move certain textfields upwards, when the keyboards would block their view - I'm sure you all know about this:
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时,这些方法停止了工作,并且提出了以下建议:
But when I recently updated to swift 4.2, these stopped working, and these suggestions came up:
将'UIKeyboardDidShow'替换为'UIResponder.keyboardDidShowNotification'&
Replace 'UIKeyboardDidShow' with 'UIResponder.keyboardDidShowNotification' &
将'UIKeyboardWillHide'替换为'UIResponder.keyboardWillHideNotification
Replace 'UIKeyboardWillHide' with 'UIResponder.keyboardWillHideNotification
但是当我按下"fix"时,出现错误(x2):
But when I pressed "fix", I get the error (x2):
类型"NSNotification.Name"没有成员"UIResponder"
Type 'NSNotification.Name' has no member 'UIResponder'
对我来说,这似乎是个虫子?那个xCode不能接受它自己的改变?有人碰到这个,知道该怎么办吗?
It kind of seems like a bug to me? That xCode can't accept it's own changes?? Anybody came across this and knows what to do?
谢谢!
推荐答案
尝试一下
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)
更多信息请使用此链接:-在此处输入链接描述
More info use this link :- enter link description here
我希望这会对您有所帮助:D谢谢
I hope this will help you :DThanks
这篇关于使用键盘将UITextField向上移动-Swift 4.2中的更改了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!