如何将自定义键盘设置为 UITextView 的默认键盘?

How do I set Custom Keyboad as a default keyboard to UITextView?

我已经创建了自定义键盘并且它工作正常。但我不知道如何将我的自定义键盘设置为特定的 UITextField。 这是我的 KeyboardViewController

import UIKit

class KeyboardViewController: UIInputViewController {

    @IBOutlet var nextKeyboardButton: UIButton!
    @IBOutlet weak var percentView: UIView!
    @IBOutlet weak var hideKeyboardButton: UIButton!

    override func updateViewConstraints() {
        super.updateViewConstraints()

        // Add custom view sizing constraints here
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton(type: .System)

        self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal)
        self.nextKeyboardButton.sizeToFit()
        self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false

        self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)

        self.view.addSubview(self.nextKeyboardButton)


        let nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
        let nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
        self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint])

        let nib = UINib(nibName: "KeyboardView", bundle: nil)
        let objects = nib.instantiateWithOwner(self, options: nil)
        view = objects[0] as! UIView;

        for view in self.view.subviews {
            if let btn = view as? UIButton {
                btn.layer.cornerRadius = 5.0
                btn.translatesAutoresizingMaskIntoConstraints = false
                //btn.addTarget(self, action: "keyPressed:", forControlEvents: .TouchUpInside)
            }
        }
    }

和其他委托方法。那我怎么称呼它呢? 实际上问题是我无法从应用程序扩展中导入自定义键盘 类。这是主要问题。我做了所有构建阶段的事情。如果我自己更换键盘,我可以使用键盘。

根据Apple Documentation

After a user chooses a custom keyboard, it becomes the keyboard for every app the user opens.

因此它不像您的应用程序特定的东西,它更像是不同语言的键盘。至于你不能为你的 UITextField 或 UITextView 指定一些特定的语言键盘,你也不能指定你的自定义键盘。

您确定在您的应用程序中需要自定义键盘而不是自定义视图来输入数据吗?关于自定义数据输入视图,您可以阅读 here