Как обновить анимацию ограничений в uitableviewcell - PullRequest
0 голосов
/ 09 апреля 2019

Я хочу увеличить высоту просмотра с помощью анимации в ячейке UITableView.Это работает, но анимация не работает, как я хочу.Мой код что-то вроде.

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

         let cell = listingTableView.dequeueReusableCell(withIdentifier: "listingTableViewCell", for: indexPath) as! listingTableViewCell

        //Charactristic expand
        let isExpand = isExpandViewArr[indexPath.row]

        if isExpand == true {

            cell.expandBtn.setImage(UIImage(named: "down-arrow"), for: .normal)
            UIView.animate(withDuration: 0.5) {
                cell.expandViewHeight.constant = 0
                self.loadViewIfNeeded()
            }
        }else{

            cell.expandBtn.setImage(UIImage(named: "up-arrow"), for: .normal)
            UIView.animate(withDuration: 0.5) {
                cell.expandViewHeight.constant = 40
                self.loadViewIfNeeded()
            }

        }

    }

Пожалуйста, проверьте экран по ссылке: https://ibb.co/XjjXRz5

Ответы [ 2 ]

2 голосов
/ 09 апреля 2019

Я считаю, что вам нужно установить cell.expandViewHeight.constant = 40 вне анимационного вызова и просто вызвать self.layoutIfNeeded() внутри. Вот так:

cell.expandViewHeight.constant = 40
UIView.animate(withDuration: 0.5) {            
    self.layoutIfNeeded()
}
0 голосов
/ 09 апреля 2019
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

    let cell = listingTableView.dequeueReusableCell(withIdentifier: "listingTableViewCell", for: indexPath) as! listingTableViewCell

    //Charactristic expand
    let isExpand = isExpandViewArr[indexPath.row]

    if isExpand == true {

        cell.expandBtn.setImage(UIImage(named: "down-arrow"), for: .normal)
        DispatchQueue.main.async {
            self.tblView.beginUpdates()
            cell.expandViewHeight.constant = 0
            self.tblView.endUpdates()
        }
    }else{

        cell.expandBtn.setImage(UIImage(named: "down-arrow"), for: .normal)
        DispatchQueue.main.async {
            self.tblView.beginUpdates()
            cell.expandViewHeight.constant = 40
            self.tblView.endUpdates()
        }
    }
}
...