作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我好像找不到我做的函数。
Error: Type 'ChatViewController' has no member 'showOrHideKeyboard'
代码:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.defaultCenter.addObserver(self, selector: #selector(ChatViewController.showOrHideKeyboard(_:)), name: UIKeyboardWillShowNotification, object: nil)
NotificationCenter.defaultCenter.addObserver(self, selector: #selector(ChatViewController.showOrHideKeyboard(_:)), name: UIKeyboardWillHideNotification, object: nil)
}
@IBOutlet weak var contraintToBottom: NSLayoutConstraint!
func showOrHideKeyboard(notification: NSNotification) {
if let keyboardInfo: Dictionary = notification.userInfo {
if notification.name == UIResponder.keyboardWillShowNotification {
UIView.animate(withDuration: 1, animations: { () in
self.contraintToBottom.constant = (keyboardInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.height
self.view.layoutIfNeeded()
}) { (completed: Bool) -> Void in
//
}
}
}
}
最佳答案
你应该用objc
标记选择器方法
改变这一行
func showOrHideKeyboard(notification: NSNotification) {
}
到这一行
@objc func showOrHideKeyboard(_ notification: NSNotification) {
}
关于ios - 类型 'ChatViewController' 没有成员 'showOrHideKeyboard',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53424389/
我好像找不到我做的函数。 Error: Type 'ChatViewController' has no member 'showOrHideKeyboard' 代码: override func v
我是一名优秀的程序员,十分优秀!