How to scroll a UITextView in a UITableViewCell to the top of the keyboard?

I need to create UITableView, which UITableViewCellcontains UITextView, very similar to the "Notes" field in the Contacts application.

When you touch the text view, the keyboard rises and the cursor scrolls correctly to the top of the keyboard. How to do it?

enter image description here

When more lines are entered, it UITextViewexpands and scrolls correctly UITableView. How it's done?

enter image description here

Stack Overflow. . . , , . , - iOS . .

+4
1

, UITableView .

- (void)keyboardWillShow
{    
     CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

     UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize.height), 0.0);

     self.tableView.contentInset = contentInsets;
     self.tableView.scrollIndicatorInsets = contentInsets;
     [self.tableView scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

}

:

- (void)keyboardWillHide:(NSNotification *)notification
{
   self.tableView.contentInset = UIEdgeInsetsZero;
   self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}

0

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


All Articles