禁用键盘上的键 [英] Disabling keys on keyboard

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

问题描述

我是Objective-C的新手,我希望限制用户从普通键盘的字母部分切换到数字/标点符号一侧.话虽这么说,我想禁用执行切换的键盘上的按钮.也许我输入了错误的搜索参数,但是我在Google上发现的很少,而在我的参考书中却发现的很少.我将如何实际禁用iOS键盘上的按钮?对于字母/数字/标点符号,只需忽略输入的输入字符即可轻松完成,但是在键盘部分之间切换的按钮会执行与返回字符相反的操作.

I am new to Objective-C, and I am looking to limit a user from switching from the alphabet portion of a normal keyboard to the numeric/punctuation side. This being said, I would like to disable the button on the keyboard that does the switch. Maybe I'm putting in the wrong search parameters, but I'm finding little on Google and even less in my reference books. How would I go about actually disabling a button on an iOS keyboard? With alpha/numeric/punctuation characters this would be easily done by just ignoring the inputed characters that were entered, but the button that switches between keyboard portions does an action as opposed to returning a character.

谢谢您的帮助!

推荐答案

您实际上可以添加和删除默认UIKeyboard

You actually can add and remove buttons of the default UIKeyboard

Internet上有一些类似这样的食谱: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.html ,例如:

There's some recipes on the Internet like this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.html and like this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html

这些帖子向您展示了如何添加按钮,但是可以使用相同的原理删除按钮.

Those posts show you how to add a button, however the same principle can be used to remove.

下面,我将向您展示其中一种解决方案:

Below I'll show you a compilation of one of the solutions:

//The UIWindow that contains the keyboard view - 
//It some situations it will be better to actually
//iterate through each window to figure out where the keyboard is, 
// but In my applications case
//I know that the second window has the keyboard so I just reference it directly
//
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] 
//                     objectAtIndex:1];

//Because we cant get access to the UIKeyboard throught the SDK we will 
// just use UIView. 
//UIKeyboard is a subclass of UIView anyways
UIView* keyboard;

//Iterate though each view inside of the selected Window
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
    //Get a reference of the current view 
    keyboard = [tempWindow.subviews objectAtIndex:i];

    //Check to see if the className of the view we have 
    //referenced is "UIKeyboard" if so then we found
    //the keyboard view that we were looking for
    if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
    {
        // Keyboard is now a UIView reference to the 
        // UIKeyboard we want. From here we can add a subview
        // to th keyboard like a new button

        //Do what ever you want to do to your keyboard here...
    }
}

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

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