xcode 创建自定义键盘并在您的 iPhone 上进行配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7189287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:05:12  来源:igfitidea点击:

Create custom keyboard and configure it on your iPhone

iphonexcodekeyboardconfigurecustomization

提问by vikas ojha

I am working on creating custom keyboardas presented by EMOJIwith having characters and pictorial icons like smileys and other day to day used symbols.So far i came to know that these symbols have unicode standards that are added to Unicode Consortium and approved by Apple.

我正在努力创建由EMOJI提供的带有字符和图形图标(如笑脸和其他日常使用的符号)的自定义键盘。到目前为止,我知道这些符号具有已添加到 Unicode 联盟并经 Apple 批准的 unicode 标准。

http://itunes.apple.com/us/app/emoji-free!/id332509635?mt=8

http://itunes.apple.com/us/app/emoji-free!/id332509635?mt=8

I need help regarding the process these symbols are registered. Is it possible to make the keyboard compatible for text inputting in all the apps installed on iphone if so How to proceed ?.

我需要有关这些符号注册过程的帮助。如果可以,是否可以使键盘与 iphone 上安装的所有应用程序中的文本输入兼容? 如何继续?。

NOTE:Are these keyboards approved by apple or apps with them gets rejected.. ...Any idea

注意:这些键盘是否得到了 Apple 或应用程序的批准,是否会被拒绝......任何想法

Any help would be appreciated .

任何帮助,将不胜感激 。

Thanks Vikas Ojha

感谢 Vikas Ojha

回答by AliSoftware

The Emoji keyboard is build-in in iOS.

表情符号键盘内置于 iOS 中。

The only thing all the "Emoji" apps existing on the AppStore (like "emoji-free!") are doing, is that they activate this keyboard in the System Preferences, because it is hidden by default. These apps don't "create and install" the keyboard itself neither do they install the icons and glyphs (symbols), the smileys are already built-in in iOS too.

AppStore 上存在的所有“表情符号”应用程序(例如“无表情符号!”)所做的唯一一件事就是在系统偏好设置中激活这个键盘,因为它默认是隐藏的。这些应用程序不会“创建和安装”键盘本身,也不会安装图标和字形(符号),表情也已经内置在 iOS 中。

For example if an iPhone user receive a text message (SMS) containing some smileys, they do will see the smiley, even if they don't have installed any "Emoji-enabler" app like "Emoji-free!".

例如,如果 iPhone 用户收到一条包含一些笑脸的短信 (SMS),他们确实会看到笑脸,即使他们没有安装任何“Emoji-enabler”应用程序,如“Emoji-free!”。



To be more precise, the emoji icons that Apple embedded in the iPhone fonts are not approved by the Unicode Standard. They are located in the "private" plane of Unicode: their codepoint is in a range that is especially reserved for private uses -- like the one Apple does by using it for these emojis -- but by definition as it is a private region, there is no dedicated name and standardized usage of these codepoint accross applications (contrary to codepoints like U+0041 which is dedicated to the glyph representing the latin letter "A")

更准确地说,苹果嵌入在 iPhone 字体中的表情符号没有得到 Unicode 标准的认可。它们位于 Unicode 的“私有”平面:它们的代码点位于一个专门为私人用途保留的范围内——就像 Apple 将它用于这些表情符号一样——但根据定义,因为它是一个私有区域,这些代码点在应用程序中没有专用名称和标准化用法(与 U+0041 之类的代码点相反,后者专用于表示拉丁字母“A”的字形)

回答by user1036272

Here's what I did in order to make a emoticons keyboard. First I created a custom view with two buttons and set self.textView.inputAccessoryView = self.accessoryView then had the two buttons do the following:

这是我为了制作表情键盘所做的事情。首先,我创建了一个带有两个按钮的自定义视图并设置 self.textView.inputAccessoryView = self.accessoryView 然后让这两个按钮执行以下操作:

- (IBAction)emoticons:(id)sender 
{
    [self.textView resignFirstResponder];
    self.textView.inputView = self.emotiview.view;
    [self.textView becomeFirstResponder];
}

- (IBAction)text:(id)sender 
{
    [self.textView resignFirstResponder];
    self.textView.inputView = nil; // sets it back to it's initial form
    [self.textView becomeFirstResponder];
}

Beneath is a snippet of the code for creating all of the buttons and putting them into a view, which is in a scrollview.

下面是用于创建所有按钮并将它们放入视图中的代码片段,该视图位于滚动视图中。

for( int i = 0; i < self.emoticonsCharacters.count; i++ )
    {
        UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake((i % 5)*50, 10 + 50*(i / 5), 45, 45);
        [button setTitle: [self.emoticonsCharacters objectAtIndex:i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(enterEmoticon:) forControlEvents:UIControlEventTouchDown];
        [self.emoticonsView1 addSubview:button];
    }

This is an array of all of the emoticons Characters.

这是所有表情符号字符的数组。

-(NSArray*) emoticonsCharacters
{
    if(!emoticonsCharacters)
    { 
        // unicode taken from http://www.easyapns.com/iphone-emoji-alerts
        emoticonsCharacters = [[NSArray alloc] initWithObjects:@"\ue415",@"\ue056",@"\ue057", @"\ue414",@"\ue405",  @"\ue418", @"\ue417", @"\ue40d", @"\ue40a", @"\ue404", @"\ue105", @"\ue409", @"\ue40e", @"\ue402", @"\ue108", @"\ue403", @"\ue058", @"\ue407", @"\ue401", @"\ue40f", @"\ue40b", @"\ue406", @"\ue413", @"\ue411", @"\ue412", @"\ue410", @"\ue107", @"\ue059", @"\ue416", @"\ue408", @"\ue40c", @"\ue11a", @"\ue10c", @"\ue32c", @"\ue32a", @"\ue32d", @"\ue328", @"\ue32b", @"\ue022", @"\ue023", @"\ue327", @"\ue329", @"\ue32e", @"\ue32f", @"\ue335", @"\ue334", @"\ue021", @"\ue337", @"\ue020", @"\ue336", @"\ue13c", @"\ue330", @"\ue331", @"\ue326", @"\ue03e", @"\ue11d", @"\ue05a", @"\ue00e", @"\ue421", @"\ue420", @"\ue00d", @"\ue010", @"\ue011", @"\ue41e", @"\ue012", @"\ue422", @"\ue22e", @"\ue22f", @"\ue231", @"\ue230", @"\ue427", @"\ue41d", @"\ue00f", @"\ue41f", @"\ue14c", @"\ue201", @"\ue115", @"\ue428", @"\ue51f", @"\ue429", @"\ue424", @"\ue423", @"\ue253", @"\ue426", @"\ue111", @"\ue425", @"\ue31e", @"\ue31f", @"\ue31d", @"\ue001", @"\ue002", @"\ue005", @"\ue004", @"\ue51a", @"\ue519", @"\ue518", @"\ue515", @"\ue516", @"\ue517", @"\ue51b", @"\ue152", @"\ue04e", @"\ue51c", @"\ue51e", @"\ue11c", @"\ue536", @"\ue003", @"\ue41c", @"\ue41b", @"\ue419", @"\ue41a", @"\ue04a", @"\ue04b", @"\ue049", @"\ue048", @"\ue04c", @"\ue13d", @"\ue443", @"\ue43e", @"\ue04f", @"\ue052", @"\ue053", @"\ue524", @"\ue52c", @"\ue52a", @"\ue531", @"\ue050", @"\ue527", @"\ue051", @"\ue10b", @"\ue52b", @"\ue52f", @"\ue528", @"\ue01a", @"\ue134", @"\ue530", @"\ue529", @"\ue526", @"\ue52d", @"\ue521", @"\ue523", @"\ue52e", @"\ue055", @"\ue525", @"\ue10a", @"\ue109", @"\ue522", @"\ue019", @"\ue054", @"\ue520", @"\ue306", @"\ue030", @"\ue304", @"\ue110", @"\ue032", @"\ue305", @"\ue303", @"\ue118", @"\ue447", @"\ue119", @"\ue307", @"\ue308", @"\ue444", @"\ue441", @"\ue436", @"\ue437", @"\ue438", @"\ue43a", @"\ue439", @"\ue43b", @"\ue117", @"\ue440", @"\ue442", @"\ue446", @"\ue445", @"\ue11b", @"\ue448", @"\ue033", @"\ue112", @"\ue325", @"\ue312", @"\ue310", @"\ue126", @"\ue127", @"\ue008", @"\ue03d", @"\ue00c", @"\ue12a", @"\ue00a", @"\ue00b", @"\ue009", @"\ue316", @"\ue129", @"\ue141", @"\ue142", @"\ue317", @"\ue128", @"\ue14b", @"\ue211", @"\ue114", @"\ue145", @"\ue144", @"\ue03f", @"\ue313", @"\ue116", @"\ue10f", @"\ue104", @"\ue103", @"\ue101", @"\ue102", @"\ue13f", @"\ue140", @"\ue11f", @"\ue12f", @"\ue031", @"\ue30e", @"\ue311", @"\ue113", @"\ue30f", @"\ue13b", @"\ue42b", @"\ue42a", @"\ue018", @"\ue016", @"\ue015", @"\ue014", @"\ue42c", @"\ue42d", @"\ue017", @"\ue013", @"\ue20e", @"\ue20c", @"\ue20f", @"\ue20d", @"\ue131", @"\ue12b", @"\ue130", @"\ue12d", @"\ue324", @"\ue301", @"\ue148", @"\ue502", @"\ue03c", @"\ue30a", @"\ue042", @"\ue040", @"\ue041", @"\ue12c", @"\ue007", @"\ue31a", @"\ue13e", @"\ue31b", @"\ue006", @"\ue302", @"\ue319", @"\ue321", @"\ue322", @"\ue314", @"\ue503", @"\ue10e", @"\ue318", @"\ue43c", @"\ue11e", @"\ue323", @"\ue31c", @"\ue034", @"\ue035", @"\ue045", @"\ue338", @"\ue047", @"\ue30c", @"\ue044", @"\ue30b", @"\ue043", @"\ue120", @"\ue33b", @"\ue33f", @"\ue341", @"\ue34c", @"\ue344", @"\ue342", @"\ue33d", @"\ue33e", @"\ue340", @"\ue34d", @"\ue339", @"\ue147", @"\ue343", @"\ue33c", @"\ue33a", @"\ue43f", @"\ue34b", @"\ue046", @"\ue345", @"\ue346", @"\ue348", @"\ue347", @"\ue34a", @"\ue349", @"\ue036", @"\ue157", @"\ue038", @"\ue153", @"\ue155", @"\ue14d", @"\ue156", @"\ue501", @"\ue158", @"\ue43d", @"\ue037", @"\ue504", @"\ue44a", @"\ue146", @"\ue50a", @"\ue505", @"\ue506", @"\ue122", @"\ue508", @"\ue509", @"\ue03b", @"\ue04d", @"\ue449", @"\ue44b", @"\ue51d", @"\ue44c", @"\ue124", @"\ue121", @"\ue433", @"\ue202", @"\ue135", @"\ue01c", @"\ue01d", @"\ue10d", @"\ue136", @"\ue42e", @"\ue01b", @"\ue15a", @"\ue159", @"\ue432", @"\ue430", @"\ue431", @"\ue42f", @"\ue01e", @"\ue039", @"\ue435", @"\ue01f", @"\ue125", @"\ue03a", @"\ue14e", @"\ue252", @"\ue137", @"\ue209", @"\ue154", @"\ue133", @"\ue150", @"\ue320", @"\ue123", @"\ue132", @"\ue143", @"\ue50b", @"\ue514", @"\ue513", @"\ue50c", @"\ue50d", @"\ue511", @"\ue50f", @"\ue512", @"\ue510", @"\ue50e", @"\ue21c", @"\ue21d", @"\ue21e", @"\ue21f", @"\ue220", @"\ue221", @"\ue222", @"\ue223", @"\ue224", @"\ue225", @"\ue210", @"\ue232", @"\ue233", @"\ue235", @"\ue234", @"\ue236", @"\ue237", @"\ue238", @"\ue239", @"\ue23b", @"\ue23a", @"\ue23d", @"\ue23c", @"\ue24d", @"\ue212", @"\ue24c", @"\ue213", @"\ue214", @"\ue507", @"\ue203", @"\ue20b", @"\ue22a", @"\ue22b", @"\ue226", @"\ue227", @"\ue22c", @"\ue22d", @"\ue215", @"\ue216", @"\ue217", @"\ue218", @"\ue228", @"\ue151", @"\ue138", @"\ue139", @"\ue13a", @"\ue208", @"\ue14f", @"\ue20a", @"\ue434", @"\ue309", @"\ue315", @"\ue30d", @"\ue207", @"\ue229", @"\ue206", @"\ue205", @"\ue204", @"\ue12e", @"\ue250", @"\ue251", @"\ue14a", @"\ue149", @"\ue23f", @"\ue240", @"\ue241", @"\ue242", @"\ue243", @"\ue244", @"\ue245", @"\ue246", @"\ue247", @"\ue248", @"\ue249", @"\ue24a", @"\ue24b", @"\ue23e", @"\ue532", @"\ue533", @"\ue534", @"\ue535", @"\ue21a", @"\ue219", @"\ue21b", @"\ue02f", @"\ue024", @"\ue025", @"\ue026", @"\ue027", @"\ue028", @"\ue029", @"\ue02a", @"\ue02b", @"\ue02c", @"\ue02d", @"\ue02e",@"\ue332",@"\ue333",@"\ue24e", @"\ue24f",@"\ue537", nil];

    }
    return emoticonsCharacters;
}

回答by AliSoftware

As an addition to my previous answer, you canhave your custom keyboard on your own app, anyway: you can define any UIView to be the "inputView" of a UITextField or UITextView (check the inputView@property in the documentation).

作为我之前回答的补充,您可以在自己的应用程序上使用自定义键盘,无论如何:您可以将任何 UIView 定义为 UITextField 或 UITextView 的“inputView”(查看inputView文档中的@property )。

For example you could write self.myTextField.inputView = myPicker;where myPicker is an UIDatePickerView you created previously (by code or in your XIB file) and when the user tap on the textfield to give it the focus (= make it the firstResponder), instead of the standard keyboard, iOS will display the UIDatePicker.

例如,您可以编写self.myTextField.inputView = myPicker;myPicker 是您之前(通过代码或在您的 XIB 文件中)创建的 UIDatePickerView 的位置,并且当用户点击文本字段以使其成为焦点时(= 使其成为 firstResponder),而不是标准键盘,iOS将显示 UIDatePicker。

But of course this is limited to your application, and for the textFields & textViews for which you configure it. That is, it is not presented as an "alternate input keyboard" you can switch onto using the "globe icon" on the keyboard, like for the Emoji keyboard or like when you switch from QWERTY to AZERTY (or any other keyboard you activated in your iPhone Settings). So this is not really the same usage as the "Emoji" case you describe.

但当然这仅限于您的应用程序,以及您为其配置的 textFields 和 textViews。也就是说,它不是作为“备用输入键盘”显示的,您可以使用键盘上的“地球图标”切换,就像表情符号键盘一样,或者当您从 QWERTY 切换到 AZERTY(或您在其中激活的任何其他键盘)时您的 iPhone 设置)。所以这与您描述的“表情符号”案例的用法并不完全相同。