【问题标题】:How to animate back an UITableView on keyboard hide?如何在键盘隐藏上为 UITableView 设置动画?
【发布时间】:2015-04-08 17:15:58
【问题描述】:

我在 UITableView 的最后一个单元格中有一个 UItextField。 我处理键盘隐藏的代码:

func keyboardWillBeHidden(aNotification:NSNotification) {
      let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
      tableView.contentInset = contentInsets
      tableView.scrollIndicatorInsets = contentInsets
}

在 iOS8 上完美运行,动画流畅。 在 iOS7 上粗暴地回到原来的位置(无动画)!

iOS7 的解决方案是什么?

【问题讨论】:

  • 你试过把所有东西都放到动画块里吗?
  • 尝试将您的代码放在 UIView 中。 + animateWithDuration:delay:options:animations:completion:function.

标签: ios uitableview swift uitextfield


【解决方案1】:

我会先试试这个。根据您的喜好调整动画持续时间。

 UIView.animateWithDuration(0.2, animations: { () -> Void in
            let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
            self.tableView.contentInset = contentInsets
            self.tableView.scrollIndicatorInsets = contentInsets
        })

【讨论】:

    【解决方案2】:

    我以前做过。它的目标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];
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-22
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多