Ios 如何在键盘隐藏上设置UITableView的动画?

Ios 如何在键盘隐藏上设置UITableView的动画?,ios,uitableview,swift,uitextfield,Ios,Uitableview,Swift,Uitextfield,我在UITableView的最后一个单元格中有一个UItextField。 处理键盘隐藏的代码: func keyboardWillBeHidden(aNotification:NSNotification) { let contentInsets: UIEdgeInsets = UIEdgeInsetsZero tableView.contentInset = contentInsets tableView.scrollIndicatorInsets = c

我在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];
    }];
}

您是否尝试过将所有内容放入动画块中?尝试将代码放入UIView中。+动画宽度持续时间:延迟:选项:动画:完成:功能。