IPhone keyboard with accessory height problems

I have a keyboard with an input connected, and I used the "Will-Show" notification of the keyboard to get the height of the keyboard.

For the first time, a text field becomes the first responder, the keyboard returns 216 for height (without the height of accessories). But for the second time, focus on the text field, returning the value is 216 + the height of the presentation of accessories.

How to get the height of the keyboard only for the height of 216 or 216 + accessories to install the framework of the user interface frame on it?

+6
source share
1 answer

I'm not sure how you make the code, but here is my working code for this:

#pragma mark - Keyboard Notification - (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *info = [notification userInfo]; NSValue *keyBoardEndFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; CGSize keyboardSize = [keyBoardEndFrame CGRectValue].size; self.keyboardSize = keyboardSize; } - (void)keyboardWillHide:(NSNotification *)notification { self.keyboardSize = CGSizeZero; } - (void) addToolBarToTextView { UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)]; toolBar.barStyle = UIBarStyleBlack; toolBar.translucent = YES; UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [doneBtn setFrame:CGRectMake(0, 7, 65, 30)]; doneBtn.titleLabel.textAlignment = NSTextAlignmentCenter; [doneBtn setTitle:@"Next" forState:UIControlStateNormal]; [doneBtn addTarget:self action:@selector(keyBoardDoneButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem * barItem = [[UIBarButtonItem alloc] initWithCustomView:doneBtn]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; toolBar.items = [NSArray arrayWithObjects: flexibleSpace, barItem, nil]; mobileTxtField.inputAccessoryView = toolBar; } -(void)viewDidLoad { [super viewDidLoad]; [self addToolBarToTextView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } 
+2
source

Source: https://habr.com/ru/post/975992/


All Articles