iOS 8 自定义键盘

iOS 8 Custom Keyboard(iOS 8 自定义键盘)
本文介绍了iOS 8 自定义键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试构建一个自定义键盘,它就像一个表情符号键盘,但键盘的数据来自一个 json 文件.解析这个json文件并获取数据后,如何让自定义键盘使用它并显示在键盘视图中,就像内置的表情符号键盘一样?现在,我遵循应用扩展键盘:自定义键盘指南,这里只有少量信息.有没有关于如何在线创建自定义表情符号键盘的教程或指南?我正在尝试的当前代码如下:

I am trying to build a custom keyboard, it's like a emoji keyboard, but the keyboard's data is from a json file. After parse this json file and get the data, how to make the custom keyboard use it and show in the keyboard view, like the emoji keyboard that built in? Right now, I follow App Extension Keyboard: Custom Keyboard guide, and there only small bits of information here. Is there any tutorial or guide about how to create a custom emoji keyboard online? The current codes I am trying are below:

class KeyboardViewController: UIInputViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        var error: NSError?
        let yanFile = NSBundle.mainBundle().pathForResource("yan", ofType: "json")
        let yanData = NSData(contentsOfFile: yanFile) as NSData
        let yanDict = NSJSONSerialization.JSONObjectWithData(yanData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
        println("dict: (yanDict)") //print nothing in console

        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton

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

    }
}

json如下:

{
    "list": 
    [
        {
            "tag": "laugh",
            "yan": 
            [
                "o(*≧▽≦)ツ┏━┓",
                "(/≥▽≤/)",
                "ヾ(o)"
            ]
        },
        {
            "tag": "wanna",
            "yan": 
            [
                "ω",
                "╰(*°▽°*)╯",
                "",
                "><",
                "ˋ▽ˊ",
                "ε",
                "υ",
                "ヾ (o ° ω ° O ) ノ",
                "(ˇˇ)",
                "(﹃)"
            ]
        }
    ]
}

推荐答案

点击新建文件->查看即可构建xib文件

You can build a xib file by clicking new file -> view

1) 在 xib 文件中创建一个 uiview 320x216,您可以将任何您想要的控件拖放到其中

1) inside the xib file create a uiview 320x216 and you can drag'n'drop whatever controls you want into it

2) 然后您可以像这样将笔尖加载到键盘的 inputView 中:

2) then you can load the nib like this into your keyboard's inputView:

// Perform custom UI setup here
UIView *layout = [[[NSBundle mainBundle] loadNibNamed:@"keyboardXib" owner:self options:nil] objectAtIndex:0];
[self.inputView addSubview:layout];

3) 我认为如果你构建一个 JSON 到键盘 api 会很棒您将键盘映射的 JSON 发送到您的应用程序并且应用程序知道如何相应地安排 inputView 上的键

3) i think it's amazing if you build a JSON to keyboard api you send a JSON of the keyboard map to your app and the app knows how to arrange the keys on the inputView accordingly

如果您构建了这个项目,请告诉我们!

let us know if you build this project!

4) 您需要做的大部分工作是解析 JSON 并从 JSON uibuttons 中显示您想要的内容,并决定它们将哪些文本插入到文本字段中

4) Most of what you need to do is parse the JSON and display the content you want from the JSON uibuttons, and also decide what text they are inserting into the text field

查看这个问题:如何快速解析 JSON 文件?

祝你好运!

这篇关于iOS 8 自定义键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

No resource found that matches the given name: attr #39;android:keyboardNavigationCluster#39;. when updating to Support Library 26.0.0(找不到与给定名称匹配的资源:attr android:keyboardNavigationCluster.更新到支持库 26.0.0 时) - IT屋-程序员软
How to resize UITextView on iOS when a keyboard appears?(出现键盘时如何在iOS上调整UITextView的大小?)
How to reliably detect if an external keyboard is connected on iOS 9?(如何可靠地检测 iOS 9 上是否连接了外部键盘?)
How to mimic Keyboard animation on iOS 7 to add quot;Donequot; button to numeric keyboard?(如何在 iOS 7 上模拟键盘动画以添加“完成数字键盘的按钮?)
How do I dismiss the iOS keyboard?(如何关闭 iOS 键盘?)
Is possible to simulate touch event using an external keyboard on ios jailbroken?(是否可以在 ios 越狱后使用外部键盘模拟触摸事件?)