UITableViewCell
のサイズをアニメーション付きで変える実装したのでそのことを書いてみます。
UITableViewCellをアニメーション付きで伸縮する
下のようにheightForRowAtIndexPath
で返す値を変更してあげればアニメーション付きで伸縮します。
tableView.beginUpdates()
でなくtableView.reloadData()
を使うとアニメーションしてくれません。
cellHeight
でなく、cell
のheight
を直接変更した場合は変な動きをします。
class MasterViewController: UITableViewController { var cellHeight = 44.0 override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return CGFloat(cellHeight) } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.beginUpdates() cellHeight = (cellHeight == 44.0 ? 100.0 : 44.0) tableView.endUpdates() } }