自定义iPhone键盘

我需要(即客户的要求)为用户提供一个自定义的键盘来input文本到文本字段和区域。 我已经有了键盘的东西,并附加到文本字段的testing,但是我想使它更通用,并像标准的iPhone键盘,即当用户select一个可编辑的文本控制时出现。 目前我的控制器知道目标和目标是不可编辑的,以防止标准键盘。

有没有办法钩入文本控件的行为,所以我很容易使用我自己的键盘?

谢谢,维克

这是一个想法:修改现有的键盘,以满足自己的需要。 首先,在屏幕上出现注册通知:

[[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]; } } 

这增加了原来的键盘上的视图,所以要确保你不透明。

你可以使用iOS 3.2或更高版本。 详细信息请查看UITextField的inputView属性。

只要您没有将应用程序提交到应用程序商店,就可以使用称为方法调配的技术在运行时dynamicreplace核心类的方法。 例如:

 @interface UIControl(CustomKeyboard) - (BOOL)__my__becomeFirstResponder @end @implementation UIControl(CustomKeyboard) - (BOOL)__my__becomeFirstResponder { BOOL becameFirstResponder = [self __my__becomeFirstResponder]; if ([self canBecomeFirstResponder]) { [MyKeyboard orderFront]; } return becameFirstResponder; } + (void)initialize { Method old = class_getInstanceMethod(self, @selector(becomeFirstResponder)); Method new = class_getInstanceMethod(self, @selector(__my__becomeFirstResponder)); method_exchangeImplementations(old, new); } @end 

在任何生产代码中不要使用这样的东西。 另外,我还没有真正testing过,所以YMMV。

这取决于你想要的习惯。 我个人只想要一个数字键盘,但不喜欢数字键盘,所以我使用标准键盘,并添加在一个标准的filter,这是选项的一部分,拒绝所有不是数字或空格的按键或删除。

我不能说苹果公司是否会喜欢这个,而且你将很难写出自己的行为,就像其他键盘一样。 如此之多,它应该被宣布为一个坏主意。

根据你的评论更新它听起来更像是你只需要创build一个有很多button的视图,并打开animation选项移动此视图。 然后它可以像键盘一样从底部向上滑动,并在被解散时再次滑动。