我为标准iOS键盘创建了一个自定义inputView,它在iOS 7和8中都能很好地工作。但当使用第三方自定义键盘时,它涵盖了我创建的inputView。它显示了自定义inputView一秒钟,并用自定义键盘视图覆盖了它。我试过几种不同的自定义键盘,但它们都有相同的问题。
是否可以在任何类型的键盘上使用inputView?如果可能的话,怎么做?
谢谢你的建议!
我遇到了同样的问题,我发现使用由视图控制器管理的视图会导致这个问题。我做了一个简单的演示来演示它:
如下所示的代码,toggleInputView
将创建一个既适用于系统键盘又适用于第三方键盘的输入视图,而toggleInputViewController
仅适用于系统键。
import UIKit
class CustomInputViewController: UIViewController {
override func viewDidLoad() {
self.view.frame = CGRect(x: 0, y: 0, width: 300, height: 200)
}
}
class ViewController: UIViewController {
var customInputViewController: CustomInputViewController?
@IBOutlet weak var textView: UITextView!
@IBAction func toggleInputView(sender: AnyObject) {
if textView.inputView == nil {
textView.inputView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 200))
} else {
textView.inputView = nil
}
self.textView.reloadInputViews()
}
@IBAction func toggleInputViewController(sender: AnyObject) {
if textView.inputView == nil {
if self.customInputViewController == nil {
self.customInputViewController = CustomInputViewController()
}
self.textView.inputView = self.customInputViewController!.view
} else {
self.textView.inputView = nil
}
self.textView.reloadInputViews()
}
}
因此,您可以通过子类UIView
构建一个输入视图来解决您的问题。