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

标签 ios swift textview uitextview

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

相关文章:

Android - 我得到 "you must supply a resource id for a textview"即使它已满

ios - 是否可以让 UIDatePicker 使用开始时间和结束时间?

swift - Alamofire Swift 3 仅上传数组中的最后一张图片

java - 如何从另一个布局(而不是作为根布局膨胀的布局)中找到 Fragment 中的ViewById?

swift - 如何在 Swift 中将默认 AnchorPoint 更改为 0.5、0.5

swift - 使用促销代码进行应用内购买 - 以及如何处理

android - 如何在 TextView 中为文本制作边框?

iphone - iPhone 上的节奏(声音变化)检测

ios - TableView 行分隔符就像在 iOS7 中的通知中心

c++ - 在 iOS 上创建实时房间后 Google Play 游戏服务崩溃