同时更新tableViewCell的高度和移动tableView

时间:2016-08-20 19:23:19

标签: ios uitableview uiscrollview swift2 contentoffset

我向上移动我的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并同时更改单元格的高度?任何线索?

0 个答案:

没有答案