我正在尝试将此代码从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);
只需用.UIResponder.keyboardDidShowNotification
替换UIResponder.keyboardDidShowNotification
,它就能解决你的问题。
最终的代码将是:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)