这是操作顺序的问题
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 之前被调用,因此第一次显示时没有滚动空间。
有没有一种有效的方法来解决这个疏忽?
最佳答案
您可以在开始期间将当前滚动位置存储在一个变量中,然后在 keyboardwillshow 通知中您可以重新滚动到存储在该变量中的任何位置。
我认为这可以让您将不同的动画保留在它们所属的位置。
关于iphone - keyboardWillShowNotification 边缘案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6810290/