简体   繁体   English

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

[英]Moving UITextField up with keyboard - changes in swift 4.2?

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)

} }

But when I recently updated to swift 4.2, these stopped working, and these suggestions came up: 但是,当我最近更新到Swift 4.2时,这些方法停止了工作,这些建议出现了:

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

Replace 'UIKeyboardWillHide' with 'UIResponder.keyboardWillHideNotification 将'UIKeyboardWillHide'替换为'UIResponder.keyboardWillHideNotification

But when I pressed "fix", I get the error (x2): 但是,当我按“修复”时,出现错误(x2):

Type 'NSNotification.Name' has no member 'UIResponder' 类型“ NSNotification.Name”没有成员“ UIResponder”

It kind of seems like a bug to me? 在我看来,这似乎是个虫子? That xCode can't accept it's own changes?? 那个xCode不能接受它自己的改变? Anybody came across this and knows what to do? 有人遇到过这个问题,知道该怎么办吗?

Thanks! 谢谢!

Try this 尝试这个

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 更多信息请使用此链接:- 在此处输入链接说明

I hope this will help you :D Thanks 希望对您有所帮助:D谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM