1

这是操作顺序的问题

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    
[nc addObserver:self 
       selector:@selector(keyboardWillShow:) 
           name:UIKeyboardWillShowNotification 
         object:nil];
[nc addObserver:self 
       selector:@selector(keyboardWillHide:) 
           name:UIKeyboardWillHideNotification 
         object:nil];

然后我向 UITableViewCell 添加一个文本框:

[textField addTarget:self 
              action:@selector(textFieldBegin:) 
    forControlEvents:UIControlEventEditingDidBegin];

[cell addSubview:textField];

在 textFieldBegin 中,我 scrollToRowAtIndexPath 移动到正在编辑的单元格。
在keyboardWillShow 中,我调整了tableView 的框架以允许使用键盘。
textFieldBegin在keyboardWillShow之前 被调用,所以第一次显示时没有滚动空间。

有没有一种方法可以解决这种疏忽?

4

2 回答 2

1

您可以在开始期间将当前滚动位置存储在变量中,然后在键盘显示通知中,您可以重新滚动到存储在该变量中的任何位置。

我认为这将允许您将不同的动画保留在它们所属的位置。

于 2011-07-24T23:03:12.063 回答
0

UIKeyboardWillShowNotification您可以对 UITextFieldDelegate 方法做出反应并在该方法中调整大小/滚动,而不是监听textFieldDidBeginEditing:,因为它是在显示键盘后调用的。

于 2011-07-24T23:04:06.330 回答