我正在尝试将此代码从Swift 3更新为Swift 4.2
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIKeyboardDidShow, object: nil);
到目前为止,我刚刚尝试了编译器给出的自动更正。结果是这样的代码:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIResponder.keyboardDidShowNotification, object: nil);
答案 0 :(得分:4)
只需将.UIResponder.keyboardDidShowNotification
替换为UIResponder.keyboardDidShowNotification
,即可解决您的问题。
最终代码将是:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)