0

I have created a custom keyboard, using some buttons. I created them using interface builder, and I create a CustomKeyboardView file..

So I have 3 files

  1. CustomKeyboardView.h
  2. CustomKeyboardView.m
  3. CustomKeyboardView.xib

I am adding this view to my UIViewController like this

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

I am seeing the custom keyboard on my screen. But I couldn't touch in any of the button.

Nothing fancy in CustomKeyBoardView.m file. I have some button handlers to address each different types of buttons in keyboard.

CustomKeyboardView.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

Some other points that might help you (to help me)

  1. I checked and rechecked the button handlers. They are wired to the IBAction.
  2. I added a button programatically to the keyboard (Done it by overriding awakeFromNib function in CustomKeyboardView.m) and this button is also shown when I add it to UIViewController. But no userInteraction on that button too.
  3. The UIViewController in question is shown in a UIPopOverController. And we use storyboard in our project.
  4. I have done added some log to see whether user interaction is enabled in kbdCustom and its super view. Answer was in the affirmative

    NSLog(@"kbdCustom.userInteractionEnabled : %d"
       , kbdCustom.userInteractionEnabled);
    NSLog(@"superView.userInteractionEnabled : %d"
       , kbdCustom.superView.userInteractionEnabled);
    

    its output is

    kbdCustom.userInteractionEnabled : 1
    superView.userInteractionEnabled : 1
    
  5. And off course, user interaction on all the button is YES, and all of them are enabled in interface builder.

  6. I have adjusted the frame of the keyboard, to move it up over the UITextField( which is receiving touch events correctly). Now when I click on the keyboard buttons, the UITextField below it is getting touches, as if the keyboard is not there.

Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
  • [This](http://stackoverflow.com/questions/10616576/a-view-loaded-from-the-nib-doesnt-receive-touch-events/10616667#10616667) question somewhat resembles this.. But I have no idea how the upvoted answer works. – Krishnabhadra Mar 20 '13 at 05:43
  • I think the problem is in the frame (Origin x,y) – Maulik Mar 20 '13 at 06:13
  • @Maulik I don't think so.. Since I am seeing the button on the scene correctly. Also I moved the keyboard to the top of the viewController's view (hiding the textfield which this keyboard populates) and when I click on the keyboard buttons, the textfield which is below the button getting the touch.. – Krishnabhadra Mar 20 '13 at 06:20

1 Answers1

5

Check for auto sizing of your view, and also set it's layer clipsToBound, then see if it's still visible. if not then that means your view have shrink to minimum size due to autoSizing, but it's subviews get displayed beyond the boundary of your baseView. In that case you can see them but can't touch.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109