我有一段在 Swift 2 中工作的代码,我尝试使用 Xcode 将代码更新到最新版本,我修复了所有问题,除了两个问题。
我有这个代码:
let loginvc: LoginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
NotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
NotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
与此配对:
func keyboardWillShow(notification: NSNotification) {
constraint.constant = -100
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
func keyboardWillHide(notification: NSNotification) {
constraint.constant = 25
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
在第一部分,我现在收到一条错误消息
类型“LoginViewController”没有成员“keyboardWillShow/Hide”
我不明白为什么它没有看到下面的方法。
有人知道这个问题的解决方案吗?