自定义键盘覆盖标准inputView

时间:2015-03-04 12:43:11

标签: ios keyboard customization

我为标准iOS键盘创建了一个自定义inputView,它在iOS 7和8中都运行良好。 但是当使用第三方自定义键盘时,它涵盖了我创建的inputView。它会显示自定义inputView一秒钟,并使用自定义键盘视图覆盖它。我尝试了几种不同的自定义键盘,它们都有同样的问题。

是否可以在任何类型的键盘上使用inputView?如果可能的话,怎么做?

感谢您的建议!

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,我发现使用视图控制器管理的视图会导致此问题。 我做了一个简单的演示来演示它:

如下所示,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构建输入视图来解决您的问题。

相关问题