我正在向上移动我的 tableView(通过设置 contentOffset)并同时更改特定(此处为第 1 行)单元格的高度,这就是为什么我得到一个摇晃的动画并且 tableView 自身恢复到默认位置(其中不是期望的行为)
我的代码:
func keyboardWillShow(notification:NSNotification) {
let userInfo:NSDictionary = notification.userInfo!
let keyboardFrame:NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.CGRectValue()
let duration = (notification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as! Double)
keyboardHeight = keyboardRectangle.height
accurateheight = accurateheight - (keyboardHeight + inputToolbar.frame.size.height) // accurateHeight is the desired CGFloat value that i want
self.tableView.beginUpdates()
self.tableView.endUpdates()
let frame = tableView.rectForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))
defaultRowHeight = frame.height
let cgpoint = CGPointMake(0, (CGFloat(-64 + defaultRowHeight)))
self.tableView.setContentOffset(cgpoint, animated: true) // here i'm moving up my tableView
}
在我的heightForRowAtIndexPath
:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 0 {
return 44
}else {
return accurate height // cell's height which i'm changing
}
}
我还尝试仅更新特定行(我正在更改高度的行),如下所示:
var indexPath = NSIndexPath(forRow: 1, inSection: 0)
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
但上述方法也不起作用,有时我的键盘没有弹出。
如何移动(向上滚动)我的 tableView 并同时更改单元格的高度?有什么线索吗?