键盘未正确显示

时间:2017-03-24 09:43:21

标签: swift keyboard

我有以下功能使键盘不能覆盖TextView,但键盘显示不正确。相反,出现了一种全黑的键盘"没有键盘键。

import logging
logging.getLogger('yapsy').setLevel(logging.DEBUG)

有人知道为什么以及如何解决它?

感谢您的时间。

2 个答案:

答案 0 :(得分:1)

尝试另一种方式。将UITextViewDelegate添加到viewController。在viewDidLoad()中添加这样的smth:

self.yourTextView1.delegate = self
self.yourTextView2.delegate = self

//For scrolling the view if keyboard on
NotificationCenter.default.addObserver(self, selector: #selector(YourViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(YourViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

并将其添加到您的ViewController:

var keyBoardAlreadyShowed = false //using this to not let app to scroll view
//if we tapped UITextField and then another UITextField
func keyboardWillShow(notification: NSNotification) {
    if !keyBoardAlreadyShowed {
        self.view.frame.origin.y -= 50 // we will scroll on it
        keyBoardAlreadyShowed = true
    }
}

func keyboardWillHide(notification: NSNotification) {
    self.view.frame.origin.y += 50
    keyBoardAlreadyShowed = false
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.view.endEditing(true)
}

希望有所帮助

答案 1 :(得分:0)

试试这个:

iOS模拟器&gt;恢复内容和设置。

清理项目,然后重新启动Xcode。