【问题标题】:Moving UITextField up with keyboard - changes in swift 4.2?用键盘向上移动 UITextField - swift 4.2 的变化?
【发布时间】:2019-04-04 14:01:44
【问题描述】:

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

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”

但是当我按下“修复”时,我得到了错误(x2):

类型“NSNotification.Name”没有成员“UIResponder”

这对我来说似乎是一个错误?那个xCode不能接受它自己的改变??有人遇到过这种情况并知道该怎么做吗?

谢谢!

【问题讨论】:

    标签: ios swift keyboard uitextfield xcode4.2


    【解决方案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 谢谢

    【讨论】:

    • 像魅力一样工作 (Y) 只是奇怪的是 xCode 不会将其更改为它本身,如果你问我!
    • @AntonBjerg 有时会在更改类层次结构时发生:D 享受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2021-11-30
    相关资源
    最近更新 更多