0

I have a UItableView that I am shrinking in size when a UIKeyboard is shown on screen, However there is the possibility that a Bluetooth keyboard can be used, I know that when a bluetooth keyboard is present UIKeyboardWillShowNotification will not be called.

So what I am doing is turning a bool on and off when the Bluetooth keyboard is connected however I am not sure how to detect when the UIKeyboard is disconnected, which is what I would like help with.

this is my code for detecting a Bluetooth keyboard.

- (void) viewdidload
//..
blueToothKeyBoardConnected = NO;
//..

- (void)UIKeyboardWillShowNotification:(NSNotification *)aNotification {

    blueToothKeyBoardConnected = YES;

}

- (BOOL)textFieldShouldBeginEditing:(UITextField*)textfield {

    // only change height if bluetoothkeyboard not present.
    if (blueToothKeyBoardConnected == YES) {
        int height = self.finishingTableView.frame.size.height;
         self.finishingTableView.frame= CGRectMake(self.finishingTableView.frame.origin.x, self.finishingTableView.frame.origin.y, self.finishingTableView.frame.size.width, 307);
    }

    //..

Effectively I would like to know when I should be setting my boolean back to NO if and when the keyboard is removed.

halfer
  • 19,824
  • 17
  • 99
  • 186
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • This might help http://stackoverflow.com/questions/2893267/how-can-i-detect-if-an-external-keyboard-is-present-on-an-ipad – Coder404 Jan 31 '14 at 22:33
  • Yea, I have read that already unfortunatly the only way to listen for the keyboard removel is to use private API's which is forbidden by apple if I plan to release the app I am making. So looking to stick within the guide lines. I have made some slight changes with the code above and put the resize code directly into **textFieldShouldBeginEditing** however this still remains very clunky when attaching and detatching the bluetooth keyboard. – HurkNburkS Jan 31 '14 at 22:45

1 Answers1

0

I had checked the height of the keyboard for detection

 -(void) keyboardWillAppear:(NSNotification *) notification
    {

        [touchView setHidden:TRUE];


        NSDictionary *userInfo = [notification userInfo];

        NSLog(@"Keyboard Dict-%@",userInfo);

        NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

        CGRect keyboardRect = [aValue CGRectValue];

        if (keyboardRect.origin.x<0 || keyboardRect.origin.x>710) {
          // connected
            return;
        }
        else {
             // disconnected
        }

    }
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86