iOS 8 Custom Keyboard(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 自定义键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 8 自定义键盘
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01