作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的键盘有问题。
如果我想在点击时继续显示键盘,我该怎么办。
我还标记了 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
}
}
图片在这里:
最佳答案
只需调用:
YourTextView.keyboardDismissMode = .none
关于ios - 如何让 UITextView 键盘不会通过点击而关闭_Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48163114/
我是一名优秀的程序员,十分优秀!