我使用一些按钮创建了一个自定义键盘。我使用界面生成器创建了它们,并创建了一个CustomKeyboardView文件..
所以我有3个文件
- 自定义键盘视图.h
 - 自定义键盘视图.m
 - 自定义键盘视图.xib
 
我正在将此视图添加到我的UIViewController喜欢中
-(void)createCustomKeyboard{
    //kbdCustom is an instance of CustomKeyboardView
    kbdCustom       =  [[[NSBundle mainBundle] loadNibNamed:@"CustomKeyBoardView" 
                             owner:self options:nil] objectAtIndex:0];
    kbdCustom.delegate   =   self;
    CGRect frame         =   kbdCustom.frame;
    frame.origin.x       =   14.0;
    frame.origin.y       =   300.0;
    kbdCustom.frame      =   frame;
    kbdCustom.backgroundColor   =   [UIColor clearColor];
    [self.view addSubview:kbdCustom];
    [self.view bringSubviewToFront:kbdCustom];
}
我在屏幕上看到自定义键盘。但我无法触摸任何按钮。
文件中没有什么花哨的  CustomKeyBoardView.m。我有一些按钮处理程序来处理键盘中每种不同类型的按钮。
自定义键盘视图.m
@implementation CustomKeyBoardView
- (IBAction)numberPressed:(id)sender {
   NSLog(@"Number pressed");
}
- (IBAction)specialCharsPressed:(id)sender {
   NSLog(@"specialCharsPressed");
}
- (IBAction)clearTextPressed:(id)sender {
   NSLog(@"clearTextPressed");
}
- (IBAction)enterButtonPressed:(id)sender {
   NSLog(@"enterButtonPressed");
}
@end
其他一些可能对你有帮助的观点(帮助我)
- 我检查并重新检查了按钮处理程序。它们连接到
IBAction. - 我以编程方式向键盘添加了一个按钮(通过覆盖中的
awakeFromNib函数来完成CustomKeyboardView.m),当我将它添加到UIViewController. 但是该按钮上也没有 userInteraction 。 - 有
UIViewController问题的显示在 a 中UIPopOverController。我们在项目中使用故事板。 我已经添加了一些日志以查看是否在
kbdCustom其超级视图中启用了用户交互。答案是肯定的NSLog(@"kbdCustom.userInteractionEnabled : %d" , kbdCustom.userInteractionEnabled); NSLog(@"superView.userInteractionEnabled : %d" , kbdCustom.superView.userInteractionEnabled);它的输出是
kbdCustom.userInteractionEnabled : 1 superView.userInteractionEnabled : 1当然,所有按钮上的用户交互都是
YES,并且所有这些都在界面生成器中启用。我已经调整了键盘的框架,将它向上移动到 UITextField(正确接收触摸事件)上。现在,当我单击键盘按钮时,它下面的 UITextField 会被触摸,就好像键盘不存在一样。