自定义 iPhone 键盘 [英] Custom iPhone Keyboard

查看:41
本文介绍了自定义 iPhone 键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要(即客户要求)为用户提供自定义键盘以在文本字段和区域中输入文本.我已经有一些东西可以做键盘并将测试附加到文本字段,但是我想让它更通用并让它像标准的 iphone 键盘一样工作,即当用户选择一个可编辑的文本控件时出现.目前我的控制器知道目标并且目标是不可编辑的以防止标准键盘.

I need (i.e. a customer requirement) to provide a custom keyboard for the user to type text into both text fields and areas. I already have something that does the keyboard and appends test to a text field, however I'd like to make it more generic and have it act like the standard iphone keyboard, i.e. appear when teh user selects an editable text control. Currently my controller knows the target and the target is uneditable to prevent the standard keyboard.

有没有办法与文本控件的行为挂钩,以便我轻松使用自己的键盘?

Is there a way to hook into the behavior of text controls so I use my own keyboard easily?

谢谢,维克

推荐答案

这里有一个想法:根据您自己的需要修改现有键盘.首先,注册以在屏幕上出现时收到通知:

Here's an idea: modify the existing keyboard to your own needs. First, register to be notified when it appears on screen:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                      selector:@selector(modifyKeyboard:)
                                      name:UIKeyboardWillShowNotification
                                      object:nil];

然后,在您的 modifyKeyboard 方法中:

Then, in your modifyKeyboard method:

- (void)modifyKeyboard:(NSNotification *)notification 
{
    UIView *firstResponder = [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)];

    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows])
        for (UIView *keyboard in [keyboardWindow subviews])
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            {
                MyFancyKeyboardView *customKeyboard = [[MyFancyKeyboardView alloc] initWithFrame: CGRectMake(0, 0, keyboard.frame.size.width, keyboard.frame.size.height);
                [keyboard addSubview: customKeyboard];
                [customKeyboard release];
            }
}

这会将您的视图添加到原始键盘的顶部,因此请确保使其不透明.

This adds your view on top of the original keyboard, so make sure you make it opaque.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆