ios - 禁用键盘上的键

标签 ios keyboard keyboard-events

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

感谢您的帮助!

最佳答案

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

网上有这样的菜谱:http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.html像这样:http://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html

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

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

//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...
    }
}

关于ios - 禁用键盘上的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9591603/

相关文章:

ios - 识别方法中的表格单元格

java - 当按下键盘上的某个键时结束程序

c# - 如何检测 WPF 中的修饰键状态?

react-native - 如何在React Native中输入输入字段时在键盘上方设置文本输入框

Javascript 跨浏览器输入层

ios - 一个 segue - 几个按钮

ios - 在没有 VOIP 的情况下使 iOS 套接字在后台模式下保持事件状态

python - 一次按下多个键让我的角色沿对角线移动

ios - 如何在我的应用程序中使用 ORKESerializer?

jQuery 和 UIWebView