I have three Cells in TableView. It has a button on the first cell and when it is pressed, the vertical size of the first cell is expanded.
In ViewController :
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 1 {
return 0
}
else if indexPath.section == 0 {
return CGFloat(expandedHeight) //700 //500
}
else if indexPath.section == 2 {
return 240
}
return 133
}
//I've modified some of my code, but it works this way.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "one", for: indexPath) as! one
return cell
}
else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "two", for: indexPath) as! two
return cell
}
else if indexPath.section == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: "thr", for: indexPath) as! thr
return cell
}
return UITableViewCell()
}
func ExpandedButtonClick(_ height: Int)
{
tableView.beginUpdates()
expandedHeight = height // 500 700 switch
tableView.endUpdates()
}
In TableViewCell (one) :
@IBAction func btnClickExpanded(_ sender: Any)
{
if let myViewController = parentViewController as? ViewController
{
if constraintExpend.constant == 500
{
constraintExpend.constant = 700
myViewController.ExpandedButtonClick(700)
}
else
{
constraintExpend.constant = 500
myViewController.ExpandedButtonClick(500)
}
}
}
Everything worked perfectly, but there is a problem.
Only the parts of the screen that I see should be animated, but the whole screen is moving. It is disturbing to see this.
What if I want to animate only the expanded part?
I want to expand while holding the screen fixed.