UITableView的最后一个单元格中有一个UItextField。我处理键盘隐藏的代码:
func keyboardWillBeHidden(aNotification:NSNotification) {
let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
tableView.contentInset = contentInsets
tableView.scrollIndicatorInsets = contentInsets
}
在iOS8上完美工作,动画流畅。在iOS7上残忍地移回原来的位置(没有动画)!
iOS7的解决方案是什么?
我会先试试这个。根据您的喜好调整动画持续时间。
UIView.animateWithDuration(0.2, animations: { () -> Void in
let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
self.tableView.contentInset = contentInsets
self.tableView.scrollIndicatorInsets = contentInsets
})
我以前也这样做过。它在目标c中。检查这个-
- (void)keyboardWillHide:(NSNotification *)sender
{
NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
[_tableView setContentInset:edgeInsets];
[_tableView setScrollIndicatorInsets:edgeInsets];
}];
}