我对键盘有疑问
如果我想在点击时继续显示键盘,我应该怎么做
我还标记了addObserver函数“ keyboardWillHide ”,但键盘也被忽略了。
感谢。
这是代码:
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name:.UIKeyboardWillShow, object: nil)
//NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:.UIKeyboardWillHide, object: nil)
}
override func keyboardWillShow(notification: NSNotification) {
super.keyboardWillShow(notification: notification)
if let userInfo:NSDictionary = notification.userInfo as NSDictionary? {
if let keyboardFrame:NSValue = userInfo.value(forKey: UIKeyboardFrameEndUserInfoKey) as? NSValue {
keyboardHeight = keyboardFrame.cgRectValue.height
}
}
setUserMode(mode: .keyboard)
updateViewFrame()
}
override func keyboardWillHide(notification: NSNotification) {
keyboardHeight = 0
updateViewFrame()
}
func updateViewFrame() {
var diffHeight:CGFloat = UIApplication.shared.statusBarFrame.height
if let nav = navigationController {
diffHeight += nav.navigationBar.height
}
let newFrame = CGRect(x: 0, y: diffHeight, width: ScreenWidth, height: ScreenHeight-keyboardHeight-diffHeight)
if view.frame.equalTo(newFrame) == false {
view.frame = newFrame
self.tableView.frame = newFrame
}
}
图片在这里:
答案 0 :(得分:0)
请致电:
YourTextView.keyboardDismissMode = .none