gpt4 book ai didi

ios - 如何让 UITextView 键盘不会通过点击而关闭_Swift

转载 作者:行者123 更新时间:2023-11-30 11:52:45 26 4
gpt4 key购买 nike

我的键盘有问题。
如果我想在点击时继续显示键盘,我该怎么办。
我还标记了 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
}
}

图片在这里:

image

最佳答案

只需调用:

YourTextView.keyboardDismissMode = .none

关于ios - 如何让 UITextView 键盘不会通过点击而关闭_Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48163114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com