0

I've been working on a project in swift, and I found an answer in objective c that perfectly does what I'd like. The solution I've been using is answered by mig70 in the post Resize and move UITableViewCell smoothly without dismissing keyboard. I've gotten most of it converted to swift, but part of the answer uses the property self.activeKeyboardSize.

There appear to be two bits of code I'm struggling with. Here is the first:

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

if (self.tableView.contentInset.bottom != 0)
    [UIView animateWithDuration:0.5 animations:^ {self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);}];

self.activeKeyboardSize = CGSizeZero; }

And here is the second

- (void) keyboardDidShow:(NSNotification*)notification {
NSDictionary* info = [notification userInfo];
self.activeKeyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

CGFloat tableViewBottom = self.tableView.frame.origin.y + self.tableView.frame.size.height;
CGFloat keyboardTop = self.view.frame.size.height - self.activeKeyboardSize.height;
CGFloat coveringVerticalSpace = tableViewBottom - keyboardTop;
if (coveringVerticalSpace <= 0)
    return;

TableViewScrollDirection scrollDirection = [self scrollToKeepEditingCellVisibleAboveVerticalPoint:self.tableView.frame.size.height - coveringVerticalSpace - UI_MARGIN_DEFAULT anchorsToVerticalPoint:NO];
if (scrollDirection == TableViewScrollUp)
    self.textControlCellHadToMoveUpToBeVisibleOverKeyboard = YES;}

The answer given doesn't state anywhere where these properties are declared or how they work.

I can't find anything in either swift or objective c that might allow me to actively change the keyboard size as demonstrated. It makes me think that it's a property that's been added in an extension. How could I go about gaining access to a property that does what is demonstrated in the answer?

Thank you!

Tiny Tim
  • 207
  • 1
  • 6

1 Answers1

1

The answer given doesn't state anywhere where these properties are declared

It cleary does. activeKeyboardSize is declared on top level of the class

CGSize activeKeyboardSize;

which is in Swift

var activeKeyboardSize : CGSize = .zero
vadian
  • 274,689
  • 30
  • 353
  • 361
  • I've spent about a day trying to figure this out, if that doesn't show how new I am to this but that finally made it click. I was under the impression that it was some property of the view controller. What's actually going on is that it was declared as a class property for what appears to be used only in the keyboardDidShow function, and the keyboardDidHide function resets it to zero. I don't know why that was so difficult for me to understand. Thank you sincerely Vadian. – Tiny Tim Apr 18 '20 at 05:18