私は自分のアプリケーションでこれを行う必要がありました-スターケンボルフの答えは私に80%をもたらしましたが、TableViewsで動作するように追加したいくつかの追加の改良がありました。
主なビットは次のとおりです。
- TableViewにはすでにインセットがあるため、それらを加算または減算する必要があります。
- また、編集しているセルが見やすい場所に表示されるようにスクロールしたいと思います。
2番目の部分では、少し間接参照が必要です。テキストフィールドはカスタムセルに属しているため、UITableViewControllerにメッセージを送信してBeginEditingメッセージに応答する必要があります。
これがすべてがどのように組み合わされるかです。UITableViewControllerの場合:
@property (nonatomic, strong) NSIndexPath *editCellIndexPath;
@property (nonatomic) bool keyboardShowing;
//....
- (void)setEditRow:(UITableViewCell *)cell
{
    self.editCellIndexPath = [self.tableView indexPathForCell:cell];
    if (self.keyboardShowing)
    {
        [self.tableView scrollToRowAtIndexPath:self.editCellIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:true];
    }
}
- (void)keyboardWillShow:(NSNotification *)sender
{
    CGSize kbSize = [[[sender userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIEdgeInsets edgeInsets = [self.tableView contentInset];
    edgeInsets.bottom += kbSize.height;
    UIEdgeInsets scrollInsets = [self.tableView scrollIndicatorInsets];
    scrollInsets.bottom += kbSize.height;
    self.keyboardShowing = true;
    [UIView animateWithDuration:duration animations:^{
        [self.tableView setContentInset:edgeInsets];
        [self.tableView setScrollIndicatorInsets:scrollInsets];
    }];
}
- (void)keyboardWillHide:(NSNotification *)sender
{
    CGSize kbSize = [[[sender userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIEdgeInsets edgeInsets = [self.tableView contentInset];
    edgeInsets.bottom -= kbSize.height;
    UIEdgeInsets scrollInsets = [self.tableView scrollIndicatorInsets];
    scrollInsets.bottom -= kbSize.height;
    self.keyboardShowing = false;
    [UIView animateWithDuration:duration animations:^{
        [self.tableView setContentInset:edgeInsets];
        [self.tableView setScrollIndicatorInsets:scrollInsets];
    }];
}
次に、各カスタムUITableViewCellsにowningControllerの弱いプロパティがあり、セルがテキスト編集されていることをコントローラーに通知します。1つの行でTextViewを使用し、別の行でTextFieldsを使用しているため、次のメソッドを使用します。
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    MyCustomTableController *itemControl = (MyCustomTableController *)self.owningController;
    [itemControl setEditRow:self];
}
と
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    MyCustomTableController *itemControl = (MyCustomTableController *)self.owningController;
    [itemControl setEditRow:self];
}
これまでのところ、これは非常にうまく機能しています。