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

查看:119
本文介绍了自定义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?

谢谢,Vic

推荐答案

这是一个想法:修改现有的键盘满足您自己的需求。首先,注册以在屏幕上显示时收到通知:

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 方法中:

- (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天全站免登陆